Skip to content

Commit 853a078

Browse files
committed
fix disqus unique urls
1 parent 5dcce45 commit 853a078

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

copy-and-fix-book-html.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class ChapterInfo:
4646
subheaders: list
4747
xrefs: list
4848

49+
@property
50+
def url(self):
51+
return f"/book/{self.href_id}.html"
52+
53+
4954

5055
def get_chapter_info():
5156
chapter_info = {}
@@ -131,13 +136,13 @@ def _prep_prev_and_next_buttons(chapter, chapter_info, buttons_html):
131136
[next_link] = buttons_div.cssselect('a.next_chapter_link')
132137
if chap_index >= 0:
133138
prev_chapinfo = list(chapter_info.values())[chap_index - 1]
134-
prev_link.set('href', f'/book/{prev_chapinfo.href_id}.html')
139+
prev_link.set('href', prev_chapinfo.url)
135140
prev_link.text = f'<< Previous - {prev_chapinfo.chapter_title}'
136141
else:
137142
prev_link.getparent().remove(prev_link)
138143
try:
139144
next_chapinfo = list(chapter_info.values())[chap_index + 1]
140-
next_link.set('href', f'/book/{next_chapinfo.href_id}.html')
145+
next_link.set('href', next_chapinfo.url)
141146
next_link.text = f'Next - {next_chapinfo.chapter_title} >>'
142147
except IndexError:
143148
next_link.getparent().remove(next_link)
@@ -156,6 +161,7 @@ def copy_chapters_across_with_fixes(chapter_info, fixed_toc):
156161
)
157162

158163
for chapter in CHAPTERS:
164+
chapinfo = chapter_info[chapter]
159165
old_contents = (BOOK_SOURCE / chapter).read_text()
160166
new_contents = fix_xrefs(old_contents, chapter, chapter_info)
161167
new_contents = fix_title(new_contents, chapter, chapter_info)
@@ -170,7 +176,11 @@ def copy_chapters_across_with_fixes(chapter_info, fixed_toc):
170176
_prep_prev_and_next_buttons(chapter, chapter_info, buttons_html)
171177
)
172178
body.append(html.fromstring(
173-
comments_html.replace('PAGE_IDENTIFIER', chapter.split('.')[0])
179+
comments_html.replace(
180+
'PAGE_IDENTIFIER', chapter.split('.')[0]
181+
).replace(
182+
'PAGE_URL', chapinfo.url
183+
)
174184
))
175185
body.append(analytics_div)
176186
fixed_contents = html.tostring(parsed)

fragments/disqus_comments.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<script>
33

44
var disqus_config = function () {
5-
this.page.url = 'https://cosmicpython.com';
5+
this.page.url = 'https://cosmicpython.comPAGE_URL';
66
this.page.identifier = 'PAGE_IDENTIFIER';
77
};
88

0 commit comments

Comments
 (0)