Skip to content

Commit 2dc5cdf

Browse files
kouloumosbitschmidty
authored andcommitted
Plugins: handle special sections case
the current recap logic cannot handle the cases where a header/section does not have list items (paragraphs that start with a hyphen) this change handles these special cases/sections and adds the recap links in the header instead of creating a nested unordered list
1 parent ec7fb36 commit 2dc5cdf

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

_includes/newsletter-references.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,29 @@
44
## News
55
*No significant news this week was found on the Bitcoin-Dev or Lightning-Dev mailing lists.*
66
{% endunless %}
7-
7+
<div>
88
{% for section in newsletter_sections %}
9-
## {{ section.name }}
10-
<ul>
11-
{% for reference in section.items %}
12-
{% assign podcast_slug = reference.podcast_slug | default: reference.slug %}
13-
<li id="{{ podcast_slug | slice: 1, podcast_slug.size }}" class="anchor-list">
14-
<p>
15-
<a href="{{ podcast_slug }}" class="anchor-list-link">●</a>
16-
{{ reference.title }}
17-
{% include functions/podcast-note.md %}
18-
</p>
19-
</li>
20-
{% endfor %}
21-
</ul>
22-
{% endfor %}
9+
<h2 id="{{ section.name | slugify: 'latin'}}"> {{ section.name }}
10+
{% if page.special_sections contains section.name %}
11+
<!-- Special sections are section that do not have list items, therefore
12+
we display the timestamp and transcript links in the header -->
13+
{% assign reference = section.items | first %}
14+
<span style="font-size:0.5em">{% include functions/podcast-note.md %}</span>
15+
{% endif %}
16+
</h2>
17+
{% unless page.special_sections contains section.name %}
18+
<ul>
19+
{% for reference in section.items %}
20+
{% assign podcast_slug = reference.podcast_slug | default: reference.slug %}
21+
<li id="{{ podcast_slug | slice: 1, podcast_slug.size }}" class="anchor-list">
22+
<p>
23+
<a href="{{ podcast_slug }}" class="anchor-list-link">●</a>
24+
{{ reference.title }}
25+
{% include functions/podcast-note.md %}
26+
</p>
27+
</li>
28+
{% endfor %}
29+
</ul>
30+
{% endunless %}
31+
{% endfor %}
32+
</div>

_plugins/recap_references_generator.rb

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,36 @@ def generate(site)
2020
# during the podcast page creation
2121
podcast.data["references"] = get_podcast_references(reference_page.content, podcast.url)
2222

23-
# Each podcast transcript splits into segements using the paragraph title
24-
# as the title of the segment. These segment splits are added manually but
25-
# we can avoid the need to also manually add their anchors by doing that here
23+
# we use this in `newsletter-references.md` to be easier to identify
24+
# special sections when iterating through the sections of the newsletter
25+
podcast.data["special_sections"] = []
26+
2627
podcast.data["references"].each do |reference|
27-
reference["has_transcript_section"] = podcast.content.sub!(/^(_.*?#{Regexp.escape(reference["title"])}.*?_)/, "{:#{reference["slug"]}-transcript}\n \\1")
28+
if reference["title"].nil?
29+
# the title of a reference derives from the nested list items
30+
# under a header/section (News, Releases and release candidates, etc.)
31+
# if there are no list items, we end up with a missing title
32+
# we use this assumption to identify special sections
33+
podcast.data["special_sections"] << reference["header"]
34+
# use the header as the title of the section
35+
reference["title"] = reference["header"]
36+
reference["slug"] = generate_slug(reference["header"])
37+
end
38+
# Each podcast transcript splits into segements using the paragraph title
39+
# as the title of the segment. These segment splits must be added manually but
40+
# we can avoid the need to also manually add their anchors by doing that here,
41+
# where we effectivily search for the segment splits and prefix them with the anchor
42+
reference["has_transcript_section"] =
43+
podcast.content.sub!(
44+
/^(_.*?#{Regexp.escape(reference["title"])}.*?_)/,
45+
"{:#{reference["slug"]}-transcript}\n \\1"
46+
)
2847
end
2948
end
3049
end
3150
end
3251

33-
def find_title(string, in_list=true, slugify=true)
52+
def find_title(string, in_list=true)
3453
# this conditional prefix is for the special case of the review club section
3554
# which is not a list item (no dash (-) at the start of the line)
3655
prefix = in_list ? / *- / : //
@@ -44,7 +63,7 @@ def find_title(string, in_list=true, slugify=true)
4463
{}
4564
else
4665
result = {"title"=> title}
47-
slug = slugify ? {"slug"=> generate_slug(title)} : {}
66+
slug = {"slug"=> generate_slug(title)}
4867
result.merge!(slug)
4968
end
5069
end
@@ -100,6 +119,11 @@ def get_podcast_references(content, target_page_url)
100119
podcast_reference.merge!(current_title)
101120
podcast_references << podcast_reference
102121

122+
if current_title.empty?
123+
# this is needed for the podcast reference mark to link to the header
124+
# of the special section
125+
current_title["slug"] = generate_slug(headers[current_header])
126+
end
103127
# Replace the whole match with the link
104128
headphones_link = "[<i class='fa fa-headphones' title='Listen to our discussion of this on the podcast'></i>]"
105129
replacement_link_to_podcast_item = "#{headphones_link}(#{target_page_url}#{current_title["podcast_slug"] || current_title["slug"]})"
@@ -109,6 +133,8 @@ def get_podcast_references(content, target_page_url)
109133
if p.sub(/^#+\s*/, "") == headers[(current_header + 1) % headers.length()]
110134
current_header += 1
111135
in_review_club_section = headers[current_header] == "Bitcoin Core PR Review Club"
136+
# reset header-specific variables
137+
current_title = {}
112138
end
113139

114140
end

0 commit comments

Comments
 (0)