mirror of
https://github.com/eternity4719/HowToLiveBetter.git
synced 2026-11-20 08:40:44 +08:00
生成时间精确到分钟并统一按北京时间显示
一天里正文常改好几轮,Release 说明和三样产物都只写日期,分不出手里是哪一版。 四处人能看见的时间统一成「2026-09-19 13:05(北京时间)」:Release 说明、 PDF 扉页与版本说明、EPUB 版本说明、离线 HTML 页脚。commit 短号原样保留。 CI 跑在 UTC 上,工作流用 date -u -d '+8 hours' 换算,不依赖 runner 的时区库; node 那三套共用 tools/lib/book.mjs 新增的 buildStamp(),按 Asia/Shanghai 格式化。 EPUB 的 dc:date 仍是纯日期(规范要求),完整时间本来就在 dcterms:modified 里。 顺带:tools/offline/build.mjs 自己又实现了一遍 ROOT/REPO/SITE/read/gitCommit, 改成从公共模块 import,删掉重复实现。
This commit is contained in:
@@ -101,7 +101,7 @@ jobs:
|
||||
run: |
|
||||
git tag -f epub-latest
|
||||
git push -f origin epub-latest
|
||||
notes="正文提交 ${GITHUB_SHA::7},生成于 $(date -u +%Y-%m-%d) UTC。EPUB、PDF、离线单文件 HTML 三样,正文每次更新后自动重新生成,下载链接固定不变。"
|
||||
notes="正文提交 ${GITHUB_SHA::7},生成于 $(date -u -d '+8 hours' +'%Y-%m-%d %H:%M')(北京时间)。EPUB、PDF、离线单文件 HTML 三样,正文每次更新后自动重新生成,下载链接固定不变。"
|
||||
if gh release view epub-latest >/dev/null 2>&1; then
|
||||
gh release edit epub-latest --title "电子书(EPUB / PDF / 离线 HTML,自动更新)" --notes "$notes"
|
||||
else
|
||||
|
||||
@@ -5,7 +5,7 @@ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
||||
import { resolve, dirname, posix } from 'node:path';
|
||||
import { deflateRawSync } from 'node:zlib';
|
||||
import { Marked } from 'marked';
|
||||
import { ROOT, REPO, SITE, TITLE, read, readBook, gitCommit, stripBackLink } from '../lib/book.mjs';
|
||||
import { ROOT, REPO, SITE, TITLE, read, readBook, gitCommit, buildStamp, stripBackLink } from '../lib/book.mjs';
|
||||
|
||||
const OUT = resolve(ROOT, process.argv[2] ?? 'dist/HowToLiveBetter.epub');
|
||||
const RELEASE = `${REPO}/releases/download/epub-latest/HowToLiveBetter.epub`;
|
||||
@@ -34,13 +34,12 @@ const pageByPath = new Map(pages.map(p => [p.src, p.file]));
|
||||
pageByPath.set('README.md', 'front.xhtml');
|
||||
|
||||
function aboutMd() {
|
||||
const date = NOW.toISOString().slice(0, 10);
|
||||
const commitLine = COMMIT ? `- 对应提交:[${COMMIT.slice(0, 7)}](${REPO}/commit/${COMMIT})` : '';
|
||||
return `# 版本说明
|
||||
|
||||
这本电子书由仓库里的 Markdown 正文自动生成,正文一改就重新生成一本。手里这本的版本:
|
||||
|
||||
- 生成日期:${date}
|
||||
- 生成时间:${buildStamp()}(北京时间)
|
||||
${commitLine}
|
||||
- 最新版下载:${RELEASE}
|
||||
- 在线检索页(按关键词、章节、证据等级和成本筛选):${SITE}
|
||||
|
||||
@@ -22,6 +22,12 @@ export function gitCommit() {
|
||||
}
|
||||
}
|
||||
|
||||
// 正文一天可能改好几轮,只给日期分不出是哪一版,所以精确到分钟。
|
||||
// CI 跑在 UTC 上,统一按北京时间显示,免得下载的人按自己那边的日期对不上。
|
||||
export function buildStamp() {
|
||||
return new Intl.DateTimeFormat('sv-SE', { timeZone: 'Asia/Shanghai', dateStyle: 'short', timeStyle: 'short' }).format(new Date());
|
||||
}
|
||||
|
||||
export function stripBackLink(md) {
|
||||
return md.replace(/^\[← 回总目录\]\([^)]*\)\s*\n/, '');
|
||||
}
|
||||
|
||||
+3
-17
@@ -4,26 +4,12 @@
|
||||
// 站内相对链接改成线上地址,侧栏图片转成 data URI,其余一个字不动。
|
||||
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
||||
import { resolve, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { ROOT, REPO, SITE, read, gitCommit, buildStamp } from '../lib/book.mjs';
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const OUT = resolve(ROOT, process.argv[2] ?? 'dist/HowToLiveBetter.html');
|
||||
const REPO = 'https://github.com/eternity4719/HowToLiveBetter';
|
||||
const SITE = 'https://eternity4719.github.io/HowToLiveBetter/';
|
||||
const DATE = new Date().toISOString().slice(0, 10);
|
||||
const STAMP = buildStamp();
|
||||
const COMMIT = gitCommit();
|
||||
|
||||
const read = p => readFileSync(resolve(ROOT, p), 'utf8');
|
||||
|
||||
function gitCommit() {
|
||||
try {
|
||||
return execSync('git rev-parse HEAD', { cwd: ROOT, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
||||
} catch {
|
||||
return process.env.GITHUB_SHA ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 正文 ----------
|
||||
const readme = read('README.md');
|
||||
const files = [...new Set([...readme.matchAll(/\]\((book\/[^)]+\.md)\)/g)].map(m => m[1]))].sort();
|
||||
@@ -56,7 +42,7 @@ html = html.replace(`src="${ad}"`, `src="data:image/webp;base64,${adData}"`);
|
||||
const foot = '<div class="foot">';
|
||||
must(foot, '页脚');
|
||||
const commitNote = COMMIT ? `,正文提交 ${COMMIT.slice(0, 7)}` : '';
|
||||
html = html.replace(foot, `${foot}离线副本,生成于 ${DATE}${commitNote};正文会继续更新,以 <a href="${SITE}">在线版</a> 为准。<br>`);
|
||||
html = html.replace(foot, `${foot}离线副本,生成于 ${STAMP}(北京时间)${commitNote};正文会继续更新,以 <a href="${SITE}">在线版</a> 为准。<br>`);
|
||||
|
||||
// 正文要在主脚本之前就位
|
||||
const mainScript = '\n<script>\n/* ---------- 调试面板';
|
||||
|
||||
+4
-4
@@ -6,13 +6,13 @@
|
||||
import { writeFileSync, mkdirSync, statSync } from 'node:fs';
|
||||
import { resolve, dirname, posix, basename } from 'node:path';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { ROOT, REPO, SITE, TITLE, read, readBook, gitCommit, stripBackLink } from '../lib/book.mjs';
|
||||
import { ROOT, REPO, SITE, TITLE, read, readBook, gitCommit, buildStamp, stripBackLink } from '../lib/book.mjs';
|
||||
|
||||
const OUT = resolve(ROOT, process.argv[2] ?? 'dist/HowToLiveBetter.pdf');
|
||||
const WORK = resolve(ROOT, 'dist/pdf-build.md');
|
||||
const PANDOC = process.env.PANDOC ?? 'pandoc';
|
||||
const TYPST = process.env.TYPST ?? 'typst';
|
||||
const DATE = new Date().toISOString().slice(0, 10);
|
||||
const STAMP = buildStamp(); // 「(北京时间)」写在模板和版本说明里,传给 pandoc 的值保持纯 ASCII
|
||||
const COMMIT = gitCommit();
|
||||
|
||||
const { description, frontMd, contentsMd, bookFiles, docFiles } = readBook();
|
||||
@@ -35,7 +35,7 @@ function aboutMd() {
|
||||
|
||||
这本 PDF 由仓库里的 Markdown 正文自动排版,正文一改就重新排一本。手里这本的版本:
|
||||
|
||||
- 生成日期:${DATE}
|
||||
- 生成时间:${STAMP}(北京时间)
|
||||
${commitLine}- 最新版下载、在线检索、提意见:${REPO}
|
||||
- 在线检索页(按关键词、章节、证据等级和成本筛选,也能存成单文件离线看):${SITE}
|
||||
|
||||
@@ -85,7 +85,7 @@ run(PANDOC, [
|
||||
'--from=gfm+attributes', '--to=typst', '--wrap=none',
|
||||
`--template=${resolve(ROOT, 'tools/pdf/template.typ')}`,
|
||||
'-V', `booktitle=${TITLE}`, '-V', `subtitle=${description}`,
|
||||
'-V', `builddate=${DATE}`, '-V', `commit=${COMMIT.slice(0, 7) || '未知'}`,
|
||||
'-V', `builddate=${STAMP}`, '-V', `commit=${COMMIT.slice(0, 7) || '未知'}`,
|
||||
'-V', `site=${SITE}`, '-V', `repo=${REPO}`,
|
||||
'-o', typFile, WORK,
|
||||
]);
|
||||
|
||||
@@ -56,7 +56,7 @@ $--
|
||||
#block(width: 80%)[#text(11.5pt, fill: luma(60))[$subtitle$]]
|
||||
#v(2cm)
|
||||
#text(10pt, fill: luma(90))[
|
||||
生成于 $builddate$ · 正文提交 $commit$ \
|
||||
生成于 $builddate$(北京时间) · 正文提交 $commit$ \
|
||||
正文每天都在改,以在线版为准:$site$ \
|
||||
在线检索、EPUB 与本 PDF 的最新版都在 $repo$
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user