From 33696afc1063447e40c536da982db78ce3e0f9cd Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 12 Apr 2024 13:35:50 +0300 Subject: [PATCH 1/4] Fix(phd.py): Change URL for Lurk --- phd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phd.py b/phd.py index a68db56..4aa206c 100644 --- a/phd.py +++ b/phd.py @@ -166,7 +166,7 @@ class phd(Template): % quote_string(query) def lurkmoar(self, query): - return "https://lurkmore.to/%s" % quote_string( + return "http://lurklurk.com/%s" % quote_string( query.replace(' ', '_'), ext_safe=',') -- 2.39.2 From 0c0058d611f55ddae8c08726acb9952e5984f8da Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 1 May 2024 17:57:08 +0300 Subject: [PATCH 2/4] Feat(blog): Encode tags A tag can be in Russian (koi8-r) with spaces. --- phd_site.tmpl | 6 +++++- reindex_blog.py | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/phd_site.tmpl b/phd_site.tmpl index 65bb058..67eb341 100644 --- a/phd_site.tmpl +++ b/phd_site.tmpl @@ -139,8 +139,12 @@ $style #end if

$body +#from urllib import quote +#def encode_tag(tag): +$quote(tag.decode('utf-8').encode('koi8-r').replace(' ', '_')) +#end def #def link_tag($tag) -$tag +$tag #end def #if $Tag
diff --git a/reindex_blog.py b/reindex_blog.py index 0f1a8f5..0b7c2a6 100755 --- a/reindex_blog.py +++ b/reindex_blog.py @@ -2,9 +2,14 @@ # -*- coding: koi8-r -*- __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2006-2021 PhiloSoft Design" +__copyright__ = "Copyright (C) 2006-2024 PhiloSoft Design" import sys, os +try: + from urllib.parse import quote +except ImportError: + from urllib import quote + from Cheetah.Template import Template from Cheetah.compat import string_type from blog_db import blog_root, load_blog, save_blog @@ -95,6 +100,8 @@ months_names_ru0 = ['', " from news import write_if_changed +def encode_tag(tag): + return quote(tag.replace(' ', '_')) def write_template(level, year, month, day, titles, tags=None): path = [blog_root] @@ -234,7 +241,8 @@ def write_template(level, year, month, day, titles, tags=None): first_tag = False else: new_text.append(' - ') - new_text.append("""%s (%d)""" % (tag, tag, count)) + new_text.append("""%s (%d)""" % ( + encode_tag(tag), tag, count)) new_text.append('''

''') @@ -362,7 +370,7 @@ linux for i, (count, tag, links) in enumerate(all_tags): new_text.append("""\
%s (%d)
-""" % (tag, tag, count)) +""" % (encode_tag(tag), tag, count)) first = all_tags[0][1] if i == 0: @@ -427,7 +435,9 @@ for i, (count, tag, links) in enumerate(all_tags): #end def $phd_site.respond(self) """) - write_if_changed(os.path.join(blog_root, "tags", tag+".tmpl"), ''.join(tag_text)) + write_if_changed(os.path.join(blog_root, "tags", + tag.replace(' ', '_') + ".tmpl"), + ''.join(tag_text)) new_text.append("""\ @@ -545,7 +555,7 @@ for item in tuple(reversed(all_titles_tags))[:10]: url_path) items.append(item) item.baseURL = baseURL - item.categoryList = tags + item.categoryList = [t.decode('koi8-r').encode('utf-8') for t in tags] body = bodies[(year, month, day, file)] body = absolute_urls(body, baseURL + url_path) try: -- 2.39.2 From 7127c2a2c65d8af2e18f2ca68328dc03e0465e60 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 21 May 2024 19:34:04 +0300 Subject: [PATCH 3/4] Fix(phd.py): Fix href to root --- phd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phd.py b/phd.py index 4aa206c..0a6a4e5 100644 --- a/phd.py +++ b/phd.py @@ -31,7 +31,7 @@ class phd(Template): if dirs_to_root: root = "../"*dirs_to_root else: - root = '' + root = './' self.root = root path = '/'.join(directories) + '/' + \ self._fileBaseName.replace(".tmpl", ".html") -- 2.39.2 From e05121e618d19083c3626cf53cf74a2232d4c2da Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 21 May 2024 19:34:27 +0300 Subject: [PATCH 4/4] Fix(Makefile): All generated files depend on `phd.py` --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5064363..f390912 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ %.py: %.tmpl umask 022; python2.7 `which cheetah` compile --encoding=koi8-r --settings='encoding="koi8-r"' --nobackup $< && compyle $@ && chmod +x $@ -%.html: %.tmpl phd_site.py +%.html: %.tmpl phd.py phd_site.py umask 022; PYTHONPATH=. PYTHONIOENCODING=koi8-r:replace python2.7 `which cheetah` fill --encoding=koi8-r --settings='encoding="koi8-r"' --nobackup --stdout $< | iconv -c -f utf-8 -t koi8-r >$@ @@ -30,7 +30,7 @@ phdru.name: blog news .PHONY: blog -blog: phd_site.py atom_10.py rss_20.py +blog: phd.py phd_site.py atom_10.py rss_20.py ./reindex_blog_ru $(MAKE) html @@ -40,7 +40,7 @@ templates = $(shell find ../htdocs/phdru.name -type f -name \*.tmpl -print) htmls = $(patsubst %.tmpl,%.html,$(templates)) .PHONY: html -html: phd_site.py $(htmls) special-templates sitemap +html: phd.py phd_site.py $(htmls) special-templates sitemap .PHONY: news -- 2.39.2