Remove anchors

This commit is contained in:
Alex Kotov 2024-09-11 08:34:15 +04:00
parent fa0c87ce13
commit c10668a64f
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 7 additions and 25 deletions

View file

@ -12,11 +12,7 @@ module Referator
end
def to_h
@to_h ||= data.merge(category:, id:, slug:, anchor:).freeze
end
def anchor
@anchor ||= "#{category}-#{slug}".freeze
@to_h ||= data.merge(category:, id:, slug:).freeze
end
private

20
test.rb
View file

@ -41,20 +41,12 @@ RAW_REFS = {
REFS = {
self: {
foo: RAW_REFS[:self][:foo].merge(
'anchor' => 'self-blog-foo',
).freeze,
bar: RAW_REFS[:self][:bar].merge(
'anchor' => 'self-blog-bar',
).freeze,
foo: RAW_REFS[:self][:foo],
bar: RAW_REFS[:self][:bar],
}.freeze,
link: {
example_com: RAW_REFS[:link][:example_com].merge(
'anchor' => 'link-example-com',
).freeze,
causa_arcana_com: RAW_REFS[:link][:causa_arcana_com].merge(
'anchor' => 'link-causa-arcana-com',
).freeze,
example_com: RAW_REFS[:link][:example_com],
causa_arcana_com: RAW_REFS[:link][:causa_arcana_com],
}.freeze,
}.freeze
@ -251,7 +243,6 @@ cmd :RENDER_FOOTNOTES, :json do |result|
"category": "self",
"id": "/blog/foo",
"slug": "blog-foo",
"anchor": "self-blog-foo",
"url": "/blog/foo.html",
"text": "Foo"
},
@ -260,7 +251,6 @@ cmd :RENDER_FOOTNOTES, :json do |result|
"category": "self",
"id": "/blog/bar",
"slug": "blog-bar",
"anchor": "self-blog-bar",
"url": "/blog/bar.html",
"text": "Bar"
}
@ -271,7 +261,6 @@ cmd :RENDER_FOOTNOTES, :json do |result|
"category": "link",
"id": "example_com",
"slug": "example-com",
"anchor": "link-example-com",
"url": "https://example.com",
"text": "Example Domain"
},
@ -280,7 +269,6 @@ cmd :RENDER_FOOTNOTES, :json do |result|
"category": "link",
"id": "causa_arcana_com",
"slug": "causa-arcana-com",
"anchor": "link-causa-arcana-com",
"url": "https://causa-arcana.com",
"text": "Causa Arcana"
}

View file

@ -4,7 +4,7 @@
<ol>
<% notes['self'].each do |note| -%>
<li id="<%= note['anchor'] %>" value="<%= note['index'] %>">
<li id="<%= "#{note['category']}-#{note['slug']}" %>" value="<%= note['index'] %>">
<a href="<%= note['id'] %>.html"><%= note['text'] %></a>
</li>
<% end -%>
@ -17,7 +17,7 @@
<ol>
<% notes['link'].each do |note| -%>
<li id="<%= note['anchor'] %>" value="<%= note['index'] %>">
<li id="<%= "#{note['category']}-#{note['slug']}" %>" value="<%= note['index'] %>">
<a href="<%= note['url'] %>"><%= note['text'] %></a>
</li>
<% end -%>

View file

@ -6,7 +6,6 @@
"category": "self",
"id": <%= String(note['id']).to_json %>,
"slug": <%= String(note['slug']).to_json %>,
"anchor": <%= String(note['anchor']).to_json %>,
"url": <%= "#{note['id']}.html".to_json %>,
"text": <%= String(note['text']).to_json %>
}<%= ',' unless index == notes['self'].count - 1 %>
@ -19,7 +18,6 @@
"category": "link",
"id": <%= String(note['id']).to_json %>,
"slug": <%= String(note['slug']).to_json %>,
"anchor": <%= String(note['anchor']).to_json %>,
"url": <%= String(note['url']).to_json %>,
"text": <%= String(note['text']).to_json %>
}<%= ',' unless index == notes['link'].count - 1 %>