『ページ』の電力料金比較表を廃止した。
理由:
- 5年近く放置していた
- 更新する気力がない
- PHP CLI で生成していたので、Cloudflare Pages の Build Image V1 が必須
Build Image V3 に移行したのでアーカイブ用ダミー生成の Python 版を書いた。
#! /usr/bin/env python3
import os
import re
basedir = '.'
postsdir = basedir + '/content/post'
archive_yearly_dir = basedir + '/content/archive_yearly'
archive_monthly_dir = basedir + '/content/archive_monthly'
archive_daily_dir = basedir + '/content/archive_daily'
if not os.path.isdir(archive_yearly_dir):
os.mkdir(archive_yearly_dir)
if not os.path.isdir(archive_monthly_dir):
os.mkdir(archive_monthly_dir)
if not os.path.isdir(archive_daily_dir):
os.mkdir(archive_daily_dir)
year_pattern = r'\d{4}'
ry = re.compile(year_pattern)
date_format_pattern = r'date\s*=\s*"\d{4}-\d{2}-\d{2}T'
rf = re.compile(date_format_pattern)
date_pattern = r'\d{4}-\d{2}-\d{2}'
rd = re.compile(date_pattern)
for year in sorted(os.listdir(postsdir)):
if os.path.isdir('%s/%s' % (postsdir, year)):
if not ry.match(year):
continue
for post in sorted(os.listdir('%s/%s' % (postsdir, year))):
if os.path.isfile('%s/%s/%s' % (postsdir, year, post)):
md = open('%s/%s/%s' % (postsdir, year, post), 'r', encoding='utf-8')
lines = md.readlines()
md.close()
for i in range(1, 10, 1):
if rf.match(lines[i]):
result = rd.search(lines[i])
postdate = result.group().split('-')
ay = open('%s/%s.md' % (archive_yearly_dir, postdate[0]), 'w', encoding='utf-8')
ay.write("%s\n%s\n%s\n%s\n%s" % ('+++', 'date = "' + postdate[0] + '-01-01T00:00:00+09:00"', 'title = "' + postdate[0] + '年"', '+++', postdate[0]))
ay.close()
am = open('%s/%s-%s.md' % (archive_monthly_dir, postdate[0], postdate[1]), 'w', encoding='utf-8')
am.write("%s\n%s\n%s\n%s\n%s" % ('+++', 'date = "' + postdate[0] + '-' + postdate[1] + '-01T00:00:00+09:00"', 'title = "' + postdate[0] + '年' + postdate[1] + '月"', '+++', postdate[0] + '-' + postdate[1]))
am.close()
ad = open('%s/%s-%s-%s.md' % (archive_daily_dir, postdate[0], postdate[1], postdate[2]), 'w', encoding='utf-8')
ad.write("%s\n%s\n%s\n%s\n%s" % ('+++', 'date = "' + postdate[0] + '-' + postdate[1] + '-' + postdate[2] + 'T00:00:00+09:00"', 'title = "' + postdate[0] + '年' + postdate[1] + '月' + postdate[2] + '日"', '+++', postdate[0] + '-' + postdate[1] + '-' + postdate[2]))
ad.close()
break
content/post/西暦/*.md の冒頭2~10行を読んで次のような行があればマッチ (Hugo で TOML front matter の1行目は「+++」と決まっているので読み飛ばす)。
date = "2025-08-15T19:34:17+09:00"
Hugo への移行当時は content/post/ 下にすべての *.md を配置していたが、今年はフィッシング詐欺の記事が多いので、年別に分けた。