refactor: moves /txt/*.txt to /*.txt

This commit is contained in:
Lewis Wynne 2026-01-31 23:29:10 +00:00
parent e2b7c18692
commit 0672a761e3
13 changed files with 17 additions and 14 deletions

View file

@ -24,13 +24,13 @@ for (const post of posts) {
}
// Count txt files and their words (excluding stats.txt which we're generating)
const txtDir = path.join(root, 'public/txt');
const txtFiles = fs.existsSync(txtDir)
? fs.readdirSync(txtDir).filter(f => f.endsWith('.txt') && f !== 'stats.txt')
const publicDir = path.join(root, 'public');
const txtFiles = fs.existsSync(publicDir)
? fs.readdirSync(publicDir).filter(f => f.endsWith('.txt') && f !== 'stats.txt')
: [];
let txtWords = 0;
for (const txt of txtFiles) {
const content = fs.readFileSync(path.join(txtDir, txt), 'utf-8');
const content = fs.readFileSync(path.join(publicDir, txt), 'utf-8');
txtWords += countWords(content);
}
@ -51,8 +51,8 @@ if (fs.existsSync(guestbookJsonFile)) {
// Calculate totals (excluding stats.txt words for now, we'll add them after generating)
const totalPages = 1 + 1 + posts.length + 1 + txtFiles.length + 1 + 1; // home, blog index, posts, txt index, txts, bookmarks, guestbook
// Read template from public/txt/stats.txt and replace placeholders
const template = fs.readFileSync(path.join(root, 'public/txt/stats.txt'), 'utf-8');
// Read template from public/stats.txt and replace placeholders
const template = fs.readFileSync(path.join(root, 'public/stats.txt'), 'utf-8');
// First pass: generate stats without stats.txt word count
let stats = template
@ -70,7 +70,7 @@ const totalWords = postWords + txtWords + statsWords;
stats = stats.replace('[WORDS]', totalWords.toString());
// Write to Vercel output
const outputDir = path.join(root, '.vercel/output/static/txt');
const outputDir = path.join(root, '.vercel/output/static');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

View file

@ -24,7 +24,7 @@ export interface TxtConfig {
}
export function getTxtDir(): string {
return path.join(process.cwd(), 'public/txt');
return path.join(process.cwd(), 'public');
}
export function loadTxtConfig(): TxtConfig {

View file

@ -19,7 +19,7 @@ export async function GET(context: APIContext) {
...txtFiles.map(txt => ({
title: txt.name,
pubDate: txt.date,
link: `/txt/${txt.name}`,
link: `/${txt.name}`,
description: txt.name,
})),
...bookmarks.map(b => ({

View file

@ -40,7 +40,7 @@ try {
<details open>
<summary>txt</summary>
<pre set:html={[
...txtFiles.slice(0, 10).map(f => formatListItem(f.date, `/txt/${f.name}`, f.name, { pinned: f.pinned })),
...txtFiles.slice(0, 10).map(f => formatListItem(f.date, `/${f.name}`, f.name, { pinned: f.pinned })),
...(txtFiles.length > 10 ? [`<a href="/txt/">+${txtFiles.length - 10} more</a>`] : [])
].join('\n')} />
</details>

View file

@ -13,7 +13,7 @@ export async function GET(context: APIContext) {
const urls = [
...posts.map(post => `/md/${getSlug(post.id)}`),
...txtFiles.map(txt => `/txt/${txt}`),
...txtFiles.map(txt => `/${txt}`),
...bookmarks.map(b => b.data.url),
];

View file

@ -17,7 +17,7 @@ export async function GET(context: APIContext) {
'/md',
...posts.map(post => `/md/${getSlug(post.id)}`),
'/txt',
...txtFiles.map(txt => `/txt/${txt}`),
...txtFiles.map(txt => `/${txt}`),
'/bookmarks',
'/guestbook',
].map(p => `${site}${p}`);

View file

@ -9,6 +9,6 @@ const txtFiles = getTxtFiles();
<details open>
<summary>txt</summary>
<pre set:html={txtFiles.map(f => formatListItem(f.date, `/txt/${f.name}`, f.name, { pinned: f.pinned })).join('\n')} />
<pre set:html={txtFiles.map(f => formatListItem(f.date, `/${f.name}`, f.name, { pinned: f.pinned })).join('\n')} />
</details>
</Layout>

View file

@ -1,5 +1,8 @@
{
"installCommand": "../install.sh",
"buildCommand": "pnpm --filter @ily/www build",
"outputDirectory": "dist"
"outputDirectory": "dist",
"redirects": [
{ "source": "/txt/now.txt", "destination": "/now.txt", "permanent": true }
]
}