Skip to content

Commit c60d11b

Browse files
committed
Use accurate times
1 parent 934ca38 commit c60d11b

File tree

9 files changed

+50
-254
lines changed

9 files changed

+50
-254
lines changed

.github/scripts/fix-timestamps

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
- uses: actions/checkout@v4
1212
with:
1313
fetch-depth: '0'
14-
- name: Fix timestamps
15-
run: bash .github/scripts/fix-timestamps
1614
#- uses: actions/cache@v4
1715
# with:
1816
# path: |

Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# syntax=docker/dockerfile:1
22
FROM node:22-alpine as node-base
33

4+
FROM node-base as timestamps
5+
RUN apk add --no-cache git bash
6+
COPY /timestamps-from-git.sh /app/timestamps-from-git.sh
7+
COPY /.git /app/.git
8+
RUN cd /app && /app/timestamps-from-git.sh '.md' > timestamps.txt
9+
410
FROM node-base as md-compiler-deps
511
COPY /md-compiler/package.json /md-compiler/package-lock.json /app/md-compiler/
612
RUN cd /app/md-compiler && npm ci --ignore-scripts
@@ -10,12 +16,11 @@ COPY /md-compiler /app/md-compiler/
1016
RUN cd /app/md-compiler && npm run compiler-build
1117

1218
FROM md-compiler-deps as md-compiler
13-
#RUN apk add --no-cache git
1419
COPY --from=md-compiler-build /app/md-compiler/out /app/md-compiler/out
1520
COPY /content /app/content
1621
COPY /app /app/app
17-
#COPY /app/.git /app/.git
18-
RUN cd /app/md-compiler && npm run compiler-run
22+
COPY --from=timestamps /app/timestamps.txt /app/timestamps.txt
23+
RUN cd /app/md-compiler && ls -l /app/timestamps.txt && npm run compiler-run
1924

2025
FROM node-base as deps
2126
COPY /package.json /package-lock.json /app/

app/sitemap.xml/route.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
import { SITE_URL } from '@/metadata';
22
import { getAllPosts, hasFeeds } from '../content';
33

4+
function clamp(min: number, max: number, value: number) {
5+
if (value < min) return min;
6+
if (value > max) return max;
7+
return value;
8+
}
9+
410
export function GET() {
511
const items = getAllPosts()
612
//.filter(({ commentStatus }) => commentStatus !== 'disabled')
713
.map(({ updatedAt, slug, summary, readingTimeMax }, id) => ({
814
url: slug,
915
updatedAt,
10-
priority:
16+
priority: clamp(
17+
0,
18+
1,
1119
0.5 +
12-
Math.min(Math.max(readingTimeMax * 0.05 - 0.1, 0), 0.3) +
13-
(slug === '' || !hasFeeds(id) ? 0 : -0.2) +
14-
(summary ? 0 : -0.2),
20+
clamp(0, 0.3, readingTimeMax * 0.05 - 0.1) +
21+
(slug === '' || !hasFeeds(id) ? 0 : -0.2) +
22+
(summary ? 0 : -0.2)
23+
),
1524
}));
1625
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
1726
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
www.ferrybig.me:
3+
build: .
4+
ports:
5+
- "2999:2999"

dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/node_modules
2-
/.git
32
/md-compiler/node_modules
43
/md-compiler/out
54
/.next
65
/out
76
/app/*.js
7+
/docker-compose.yml

md-compiler/parser/fileTransform.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,28 @@ function readSummary(tree: Root) {
6060
return text;
6161
}
6262

63+
const cacheKeyTimestamps = Symbol('cache-timestamps');
6364
const cacheKey = Symbol('cache');
6465

6566
async function processFile(paths: string[], config: RunningConfig): Promise<CompileResultsArticle> {
6667
const file = join(config.inputDir, ...paths);
6768
try {
68-
const modificationTime = (await stat(file)).mtimeMs;
69+
console.log(file);
70+
const timestamps = await config.cache.memo(async () => {
71+
const t: Record<string, number> = {};
72+
try {
73+
const timestampData = await readFile('../timestamps.txt', { encoding: 'utf8' });
74+
if (timestampData.length === 0) throw new Error('Timestamp file is empty');
75+
for (const row of timestampData.split('\0')) {
76+
const [value, key] = row.split('\t', 2);
77+
t['../' + key] = parseInt(value, 10) * 1000;
78+
}
79+
} catch (e) {
80+
if (!(e && typeof e === 'object' && 'code' in e && e.code === 'ENOENT')) throw e;
81+
}
82+
return t;
83+
}, cacheKeyTimestamps, []);
84+
const modificationTime = timestamps[file] ?? (await stat(file)).mtimeMs;
6985

7086
return await config.cache.memo(async () => {
7187
const raw: string = await readFile(file, { encoding: 'utf8' });

oldsitemap.xml

Lines changed: 0 additions & 236 deletions
This file was deleted.

timestamps-from-git.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -e
2+
git ls-tree -r --name-only HEAD | grep "$1" | while IFS= read -r filename; do
3+
echo "Processing $filename" >&2
4+
unixtime=$(git log -1 --format="%at" -- "$filename")
5+
printf '%s\t%s\0' "$unixtime" "$filename"
6+
done

0 commit comments

Comments
 (0)