Skip to content

Commit

Permalink
Added title liquid pre-rendering to the link generation phase
Browse files Browse the repository at this point in the history
- autolink/tooltip generation now can handle liquid variables in titles
Signed-off-by: Hofi <[email protected]>
  • Loading branch information
HofiOne committed Jun 3, 2024
1 parent b3fa9aa commit 4fe298c
Showing 1 changed file with 10 additions and 4 deletions.
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

0 comments on commit 4fe298c

Please sign in to comment.