Skip to content

Commit 035a19d

Browse files
authored
Autolink tooltip does not work directly for titles with liquid markdown expressions 61 (#78)
Added title liquid pre-rendering to the link generation phase - autolink/tooltip generation now can handle liquid variables in titles Signed-off-by: Hofi <[email protected]>
2 parents 22488e7 + 4fe298c commit 035a19d

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

_config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ include:
5656
- assets/js/main.min.js
5757
# Only lunr is not included now to main.min.js
5858
- assets/js/lunr
59-
# site.data.links input
59+
# Input of site.data.links
6060
- _data/links/
6161
exclude:
6262
- .reftime
@@ -178,9 +178,11 @@ search_from_masthead: true
178178

179179
search_provider: lunr
180180
lunr:
181-
# No we have all the valuable content in collections
181+
# No we have all the valuable content in collections (collection.docs)
182+
# that lunr indexes by default if search: true
182183
# Standalone pages like, sitemap.xml, 404, etc. should not be searched
183184
search_within_pages: false
185+
test_text_1: "abrakadabra"
184186

185187
# search_provider: algolia
186188
# algolia:

_js/lunr/lunr-en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $(document).ready(function() {
8181
'<div class="list__item">' +
8282
'<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">' +
8383
'<h2 class="archive__item-title" itemprop="headline">' +
84-
'<a href="' + removeExtension(tore[ref].url) + '" onclick="searchResultLinkClickHandler(event)" rel="permalink">' + store[ref].title + '</a>' +
84+
'<a href="' + removeExtension(store[ref].url) + '" onclick="searchResultLinkClickHandler(event)" rel="permalink">' + store[ref].title + '</a>' +
8585
'</h2>' +
8686
'<div class="archive__item-teaser">' +
8787
'<img src="' + store[ref].teaser + '" alt="">' +

_plugins/generate_links.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ def register_id(page, id, title, ids, titles)
4444
end
4545
end
4646

47+
def render_title(page, title)
48+
context = page.site.site_payload['site']
49+
template = Liquid::Template.parse(title)
50+
return template.render('site' => context)
51+
end
52+
4753
public
48-
54+
4955
def generate_links(page, ids, titles)
5056
#puts page.relative_path
5157
# Must have to get it parsed by jekyll, these links will be part of the site.data.links array as well, do not touch them
@@ -81,7 +87,7 @@ def generate_links(page, ids, titles)
8187
link_data = {
8288
"id" => page_id + "##{heading_id}",
8389
"url" => page_url + "##{heading_id}",
84-
"title" => '"' + heading.text + '"',
90+
"title" => '"' + render_title(page, heading.text) + '"',
8591
}
8692
#register_id(page, link_data["id"], link_data["title"], ids, titles)
8793

@@ -104,7 +110,7 @@ def generate_links(page, ids, titles)
104110
link_data = {
105111
"id" => anchor_id,
106112
"url" => page_url + "##{anchor_name}",
107-
"title" => '"' + (anchor_text.empty? ? anchor_id : anchor_text) + '"',
113+
"title" => '"' + (anchor_text.empty? ? anchor_id : render_title(page, anchor_text)) + '"',
108114
}
109115
#register_id(page, link_data["id"], link_data["title"], ids, titles)
110116

@@ -114,7 +120,7 @@ def generate_links(page, ids, titles)
114120
end
115121

116122
# Create links data for the page itself too
117-
page_title = page.data["title"]
123+
page_title = render_title(page, page.data["title"])
118124
page_link_data = {
119125
"id" => page_id,
120126
"url" => page_url,

doc/_doc-guide/02_Tools/01_Self_made_tools/01_Tests/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ options {
6161
};
6262
```
6363

64+
## Tests of custom markdown in header [[source]] and [[with turumturum id|doc-jekyll-extensions#titleid-markdown-extension]]
65+
66+
## Tests of liquid expression {{ site.lunr.test_text_1 }} in header of {{ site.title }}
67+
6468
---------------------
6569

6670
Introduction to {{ site.product.short_name }} is a test for pages without description/subtitle, but text part between the title and the first heading which can have tooltips too this way.

0 commit comments

Comments
 (0)