Skip to content

Commit 4fe298c

Browse files
committed
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]>
1 parent b3fa9aa commit 4fe298c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

_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,

0 commit comments

Comments
 (0)