Skip to content

Commit c1c765e

Browse files
committed
Plugins: extract slug generation to common util
1 parent 080dcf9 commit c1c765e

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

_plugins/auto-anchor.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def auto_anchor(content)
1616
## No match, pass item through unchanged
1717
string
1818
else
19-
## Remove double-quotes from titles before attempting to slugify
20-
title.gsub!('"', '')
21-
## Use Liquid/Jekyll slugify filter to choose our id
22-
slug = "\#{{ \"#{title}\" | slugify: 'latin' }}"
19+
slug = generate_slug(title)
2320
id_prefix = "- {:#{slug} .anchor-list} <a href=\"#{slug}\" class=\"anchor-list-link\">●</a>"
2421
string.sub!(/-/, id_prefix)
2522
end

_plugins/common_utils.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def generate_slug(title)
2+
## Remove double-quotes from titles before attempting to slugify
3+
title.gsub!('"', '')
4+
## Use Liquid/Jekyll slugify filter to choose our id
5+
liquid_string = "\#{{ \"#{title}\" | slugify: 'latin' }}"
6+
slug = Liquid::Template.parse(liquid_string)
7+
# An empty context is used here because we only need to parse the liquid
8+
# string and don't require any additional variables or data.
9+
slug.render(Liquid::Context.new)
10+
end

_plugins/recap_references_generator.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ def generate(site)
3030
end
3131
end
3232

33-
def generate_slug(title)
34-
## Remove double-quotes from titles before attempting to slugify
35-
title.gsub!('"', '')
36-
## Use Liquid/Jekyll slugify filter to choose our id
37-
liquid_string = "\#{{ \"#{title}\" | slugify: 'latin' }}"
38-
slug = Liquid::Template.parse(liquid_string)
39-
# An empty context is used here because we only need to parse the liquid
40-
# string and don't require any additional variables or data.
41-
slug.render(Liquid::Context.new)
42-
end
43-
4433
def find_title(string, in_list=true, slugify=true)
4534
# this conditional prefix is for the special case of the review club section
4635
# which is not a list item (no dash (-) at the start of the line)

0 commit comments

Comments
 (0)