Skip to content

Commit

Permalink
Autolink tooltip does not work directly for titles with liquid markdo…
Browse files Browse the repository at this point in the history
…wn expressions 61 (syslog-ng#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]>
  • Loading branch information
mrgarris0n committed Jun 4, 2024
2 parents 22488e7 + 4fe298c commit 035a19d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ include:
- assets/js/main.min.js
# Only lunr is not included now to main.min.js
- assets/js/lunr
# site.data.links input
# Input of site.data.links
- _data/links/
exclude:
- .reftime
Expand Down Expand Up @@ -178,9 +178,11 @@ search_from_masthead: true

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

# search_provider: algolia
# algolia:
Expand Down
2 changes: 1 addition & 1 deletion _js/lunr/lunr-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $(document).ready(function() {
'<div class="list__item">' +
'<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">' +
'<h2 class="archive__item-title" itemprop="headline">' +
'<a href="' + removeExtension(tore[ref].url) + '" onclick="searchResultLinkClickHandler(event)" rel="permalink">' + store[ref].title + '</a>' +
'<a href="' + removeExtension(store[ref].url) + '" onclick="searchResultLinkClickHandler(event)" rel="permalink">' + store[ref].title + '</a>' +
'</h2>' +
'<div class="archive__item-teaser">' +
'<img src="' + store[ref].teaser + '" alt="">' +
Expand Down
14 changes: 10 additions & 4 deletions _plugins/generate_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ def register_id(page, id, title, ids, titles)
end
end

def render_title(page, title)
context = page.site.site_payload['site']
template = Liquid::Template.parse(title)
return template.render('site' => context)
end

public

def generate_links(page, ids, titles)
#puts page.relative_path
# 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
Expand Down Expand Up @@ -81,7 +87,7 @@ def generate_links(page, ids, titles)
link_data = {
"id" => page_id + "##{heading_id}",
"url" => page_url + "##{heading_id}",
"title" => '"' + heading.text + '"',
"title" => '"' + render_title(page, heading.text) + '"',
}
#register_id(page, link_data["id"], link_data["title"], ids, titles)

Expand All @@ -104,7 +110,7 @@ def generate_links(page, ids, titles)
link_data = {
"id" => anchor_id,
"url" => page_url + "##{anchor_name}",
"title" => '"' + (anchor_text.empty? ? anchor_id : anchor_text) + '"',
"title" => '"' + (anchor_text.empty? ? anchor_id : render_title(page, anchor_text)) + '"',
}
#register_id(page, link_data["id"], link_data["title"], ids, titles)

Expand All @@ -114,7 +120,7 @@ def generate_links(page, ids, titles)
end

# Create links data for the page itself too
page_title = page.data["title"]
page_title = render_title(page, page.data["title"])
page_link_data = {
"id" => page_id,
"url" => page_url,
Expand Down
4 changes: 4 additions & 0 deletions doc/_doc-guide/02_Tools/01_Self_made_tools/01_Tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ options {
};
```

## Tests of custom markdown in header [[source]] and [[with turumturum id|doc-jekyll-extensions#titleid-markdown-extension]]

## Tests of liquid expression {{ site.lunr.test_text_1 }} in header of {{ site.title }}

---------------------

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.
Expand Down

0 comments on commit 035a19d

Please sign in to comment.