Skip to content

Commit

Permalink
Use accurate times
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrybig committed Sep 4, 2024
1 parent 934ca38 commit c60d11b
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 254 deletions.
7 changes: 0 additions & 7 deletions .github/scripts/fix-timestamps

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Fix timestamps
run: bash .github/scripts/fix-timestamps
#- uses: actions/cache@v4
# with:
# path: |
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# syntax=docker/dockerfile:1
FROM node:22-alpine as node-base

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / tests / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

FROM node-base as timestamps

Check warning on line 4 in Dockerfile

View workflow job for this annotation

GitHub Actions / tests / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
RUN apk add --no-cache git bash
COPY /timestamps-from-git.sh /app/timestamps-from-git.sh
COPY /.git /app/.git
RUN cd /app && /app/timestamps-from-git.sh '.md' > timestamps.txt

FROM node-base as md-compiler-deps
COPY /md-compiler/package.json /md-compiler/package-lock.json /app/md-compiler/
RUN cd /app/md-compiler && npm ci --ignore-scripts
Expand All @@ -10,12 +16,11 @@ COPY /md-compiler /app/md-compiler/
RUN cd /app/md-compiler && npm run compiler-build

FROM md-compiler-deps as md-compiler

Check warning on line 18 in Dockerfile

View workflow job for this annotation

GitHub Actions / tests / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
#RUN apk add --no-cache git
COPY --from=md-compiler-build /app/md-compiler/out /app/md-compiler/out
COPY /content /app/content
COPY /app /app/app
#COPY /app/.git /app/.git
RUN cd /app/md-compiler && npm run compiler-run
COPY --from=timestamps /app/timestamps.txt /app/timestamps.txt
RUN cd /app/md-compiler && ls -l /app/timestamps.txt && npm run compiler-run

FROM node-base as deps

Check warning on line 25 in Dockerfile

View workflow job for this annotation

GitHub Actions / tests / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
COPY /package.json /package-lock.json /app/
Expand Down
17 changes: 13 additions & 4 deletions app/sitemap.xml/route.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { SITE_URL } from '@/metadata';
import { getAllPosts, hasFeeds } from '../content';

function clamp(min: number, max: number, value: number) {
if (value < min) return min;
if (value > max) return max;
return value;
}

export function GET() {
const items = getAllPosts()
//.filter(({ commentStatus }) => commentStatus !== 'disabled')
.map(({ updatedAt, slug, summary, readingTimeMax }, id) => ({
url: slug,
updatedAt,
priority:
priority: clamp(
0,
1,
0.5 +
Math.min(Math.max(readingTimeMax * 0.05 - 0.1, 0), 0.3) +
(slug === '' || !hasFeeds(id) ? 0 : -0.2) +
(summary ? 0 : -0.2),
clamp(0, 0.3, readingTimeMax * 0.05 - 0.1) +
(slug === '' || !hasFeeds(id) ? 0 : -0.2) +
(summary ? 0 : -0.2)
),
}));
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
www.ferrybig.me:
build: .
ports:
- "2999:2999"
2 changes: 1 addition & 1 deletion dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/node_modules
/.git
/md-compiler/node_modules
/md-compiler/out
/.next
/out
/app/*.js
/docker-compose.yml
18 changes: 17 additions & 1 deletion md-compiler/parser/fileTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,28 @@ function readSummary(tree: Root) {
return text;
}

const cacheKeyTimestamps = Symbol('cache-timestamps');
const cacheKey = Symbol('cache');

async function processFile(paths: string[], config: RunningConfig): Promise<CompileResultsArticle> {
const file = join(config.inputDir, ...paths);
try {
const modificationTime = (await stat(file)).mtimeMs;
console.log(file);
const timestamps = await config.cache.memo(async () => {
const t: Record<string, number> = {};
try {
const timestampData = await readFile('../timestamps.txt', { encoding: 'utf8' });
if (timestampData.length === 0) throw new Error('Timestamp file is empty');
for (const row of timestampData.split('\0')) {
const [value, key] = row.split('\t', 2);
t['../' + key] = parseInt(value, 10) * 1000;
}
} catch (e) {
if (!(e && typeof e === 'object' && 'code' in e && e.code === 'ENOENT')) throw e;
}
return t;
}, cacheKeyTimestamps, []);
const modificationTime = timestamps[file] ?? (await stat(file)).mtimeMs;

return await config.cache.memo(async () => {
const raw: string = await readFile(file, { encoding: 'utf8' });
Expand Down
236 changes: 0 additions & 236 deletions oldsitemap.xml

This file was deleted.

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

0 comments on commit c60d11b

Please sign in to comment.