Skip to content

Commit

Permalink
style: [!note]와 연관되지 않은 링크 처리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Monixc committed Oct 21, 2024
1 parent ffcbb2a commit f57cf43
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 60 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ gem "jekyll", "~> 4.3"
gem "jekyll-last-modified-at", git: "https://github.com/maximevaillancourt/jekyll-last-modified-at", branch: "add-support-for-files-in-git-submodules"
gem "webrick", "~> 1.8"
gem "nokogiri"
gem 'wdm', '>= 0.1.0' if Gem.win_platform?
25 changes: 15 additions & 10 deletions _layouts/note.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,30 @@ <h1>{{ page.title }}</h1>
<div id="notes-entry-container">
<content>
{{ content }}
<p>This line appears after every note.</p>

</content>

<side style="font-size: 0.9em">
<h3 style="margin-bottom: 1em">Notes mentioning this note</h3>
<h3 style="margin-bottom: 1em">연관된 노트</h3>
{% if page.backlinks.size > 0 %}
<div style="display: grid; grid-gap: 1em; grid-template-columns: repeat(1fr);">
{% for backlink in page.backlinks %}
{% for backlink in page.backlinks %}
<div class="backlink-box">
<a class="internal-link" href="{{ site.baseurl }}{{ backlink.url }}{%- if site.use_html_extension -%}.html{%- endif -%}">{{ backlink.title }}</a><br>
<div style="font-size: 0.9em">{{ backlink.excerpt | strip_html | truncatewords: 20 }}</div>
<a class="internal-link"
href="{{ site.baseurl }}{{ backlink.url }}{%- if site.use_html_extension -%}.html{%- endif -%}">
<strong>{{ backlink.title }}</strong>
</a><br>
<div style="font-size: 0.9em">
{{ backlink.excerpt | strip_html | truncatewords: 20 | replace: "[[", "<span style='color: #888;'>" |
replace: "]]", "</span>" }}
</div>
</div>
{% endfor %}
{% endfor %}
</div>
{% else %}

<div style="font-size: 0.9em">
<p>
There are no notes linking to this note.
연관된 노트가 없습니다. 추가하러 가세요.
</p>
</div>
{% endif %}
Expand All @@ -42,6 +47,6 @@ <h3 style="margin-bottom: 1em">Notes mentioning this note</h3>

<hr>

<p>Here are all the notes in this garden, along with their links, visualized as a graph.</p>
<p style="font-weight: bold;">AWS Universe</p>

{% include notes_graph.html %}
{% include notes_graph.html %}
13 changes: 0 additions & 13 deletions _notes/AWS 정리/AWS 정리.md

This file was deleted.

2 changes: 1 addition & 1 deletion _notes/AWS 정리/클라우드 서비스.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
[[클라우드 컴퓨팅]]은 서비스 제공 형태에 따라 [[클라우드 구축 모델#퍼블릭 클라우드]], [[클라우드 구축 모델#프라이빗 클라우드]], [[클라우드 구축 모델#하이브리드 클라우드]]로 구분된다.

### 서비스 유형
서비스 관리 주체와 수준에 따라 클라우드 서비스를 [[IaaS]], [[PaaS]], [[SaaS ]]로 구분할 수 있다.
서비스 관리 주체와 수준에 따라 클라우드 서비스를 [[IaaS]], [[PaaS]], [[SaaS]] 로 구분할 수 있다.

54 changes: 19 additions & 35 deletions _plugins/bidirectional_links_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,33 @@ def generate(site)
end

new_href = "#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}"
anchor_tag = "<a class='internal-link' href='#{new_href}'>\\1</a>"

# Replace double-bracketed links with label using note title
# [[A note about cats|this is a link to the note about cats]]
current_note.content.gsub!(
/\[\[#{note_title_regexp_pattern}\|(.+?)(?=\])\]\]/i,
anchor_tag
)

# Replace double-bracketed links with label using note filename
# [[cats|this is a link to the note about cats]]
current_note.content.gsub!(
/\[\[#{title_from_data}\|(.+?)(?=\])\]\]/i,
anchor_tag
)
# Handle links with headers
current_note.content.gsub!(/\[\[(.*?)#(.*?)\]\]/) do |match|
link_text = $1
header = $2
note = all_docs.find { |n| n.data['title']&.downcase == link_text.downcase }
if note
new_href = "#{site.baseurl}#{note.url}#{link_extension}##{header.downcase.gsub(' ', '-')}"
"<a class='internal-link' href='#{new_href}'>#{header}</a>"
else
"<span class='invalid-link'>#{header}</span>"
end
end

# Replace double-bracketed links using note title
# [[a note about cats]]
current_note.content.gsub!(
/\[\[(#{title_from_data})\]\]/i,
anchor_tag
)
# Handle regular links
anchor_tag = "<a class='internal-link' href='#{new_href}'>\\1</a>"

# Replace double-bracketed links using note filename
# [[cats]]
current_note.content.gsub!(
/\[\[(#{note_title_regexp_pattern})\]\]/i,
/\[\[(#{note_title_regexp_pattern}|#{title_from_data})\]\]/i,
anchor_tag
)
end

# At this point, all remaining double-bracket-wrapped words are
# pointing to non-existing pages, so let's turn them into disabled
# links by greying them out and changing the cursor
current_note.content = current_note.content.gsub(
/\[\[([^\]]+)\]\]/i, # match on the remaining double-bracket links
<<~HTML.delete("\n") # replace with this HTML (\\1 is what was inside the brackets)
<span title='There is no note that matches this link.' class='invalid-link'>
<span class='invalid-link-brackets'>[[</span>
\\1
<span class='invalid-link-brackets'>]]</span></span>
HTML
)
# Handle links to non-existing pages
current_note.content.gsub!(/\[\[([^\]]+)\]\]/) do |match|
"<span class='invalid-link' title='There is no note that matches this link'>#{$1}</span>"
end
end

# Identify note backlinks and add them to each note
Expand Down
3 changes: 3 additions & 0 deletions _plugins/markdown-highlighter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@

def replace(doc)
doc.content.gsub!(/==+([^ ](.*?)?[^ .=])==+/, "<mark>\\1</mark>")
doc.content.gsub!(/>\s*\[!note\]\s*(.*)$/) do |match|
"> ⭐ <span style='display:none;'>#{$1.strip}</span>"
end
end
Empty file added bundle
Empty file.
Empty file added spell_checker)'
Empty file.

0 comments on commit f57cf43

Please sign in to comment.