refactor: moves /txt/*.txt to /*.txt
This commit is contained in:
parent
e2b7c18692
commit
0672a761e3
13 changed files with 17 additions and 14 deletions
|
|
@ -24,13 +24,13 @@ for (const post of posts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count txt files and their words (excluding stats.txt which we're generating)
|
// Count txt files and their words (excluding stats.txt which we're generating)
|
||||||
const txtDir = path.join(root, 'public/txt');
|
const publicDir = path.join(root, 'public');
|
||||||
const txtFiles = fs.existsSync(txtDir)
|
const txtFiles = fs.existsSync(publicDir)
|
||||||
? fs.readdirSync(txtDir).filter(f => f.endsWith('.txt') && f !== 'stats.txt')
|
? fs.readdirSync(publicDir).filter(f => f.endsWith('.txt') && f !== 'stats.txt')
|
||||||
: [];
|
: [];
|
||||||
let txtWords = 0;
|
let txtWords = 0;
|
||||||
for (const txt of txtFiles) {
|
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);
|
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)
|
// 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
|
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
|
// Read template from public/stats.txt and replace placeholders
|
||||||
const template = fs.readFileSync(path.join(root, 'public/txt/stats.txt'), 'utf-8');
|
const template = fs.readFileSync(path.join(root, 'public/stats.txt'), 'utf-8');
|
||||||
|
|
||||||
// First pass: generate stats without stats.txt word count
|
// First pass: generate stats without stats.txt word count
|
||||||
let stats = template
|
let stats = template
|
||||||
|
|
@ -70,7 +70,7 @@ const totalWords = postWords + txtWords + statsWords;
|
||||||
stats = stats.replace('[WORDS]', totalWords.toString());
|
stats = stats.replace('[WORDS]', totalWords.toString());
|
||||||
|
|
||||||
// Write to Vercel output
|
// 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)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export interface TxtConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTxtDir(): string {
|
export function getTxtDir(): string {
|
||||||
return path.join(process.cwd(), 'public/txt');
|
return path.join(process.cwd(), 'public');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadTxtConfig(): TxtConfig {
|
export function loadTxtConfig(): TxtConfig {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export async function GET(context: APIContext) {
|
||||||
...txtFiles.map(txt => ({
|
...txtFiles.map(txt => ({
|
||||||
title: txt.name,
|
title: txt.name,
|
||||||
pubDate: txt.date,
|
pubDate: txt.date,
|
||||||
link: `/txt/${txt.name}`,
|
link: `/${txt.name}`,
|
||||||
description: txt.name,
|
description: txt.name,
|
||||||
})),
|
})),
|
||||||
...bookmarks.map(b => ({
|
...bookmarks.map(b => ({
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ try {
|
||||||
<details open>
|
<details open>
|
||||||
<summary>txt</summary>
|
<summary>txt</summary>
|
||||||
<pre set:html={[
|
<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>`] : [])
|
...(txtFiles.length > 10 ? [`<a href="/txt/">+${txtFiles.length - 10} more</a>`] : [])
|
||||||
].join('\n')} />
|
].join('\n')} />
|
||||||
</details>
|
</details>
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export async function GET(context: APIContext) {
|
||||||
|
|
||||||
const urls = [
|
const urls = [
|
||||||
...posts.map(post => `/md/${getSlug(post.id)}`),
|
...posts.map(post => `/md/${getSlug(post.id)}`),
|
||||||
...txtFiles.map(txt => `/txt/${txt}`),
|
...txtFiles.map(txt => `/${txt}`),
|
||||||
...bookmarks.map(b => b.data.url),
|
...bookmarks.map(b => b.data.url),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ export async function GET(context: APIContext) {
|
||||||
'/md',
|
'/md',
|
||||||
...posts.map(post => `/md/${getSlug(post.id)}`),
|
...posts.map(post => `/md/${getSlug(post.id)}`),
|
||||||
'/txt',
|
'/txt',
|
||||||
...txtFiles.map(txt => `/txt/${txt}`),
|
...txtFiles.map(txt => `/${txt}`),
|
||||||
'/bookmarks',
|
'/bookmarks',
|
||||||
'/guestbook',
|
'/guestbook',
|
||||||
].map(p => `${site}${p}`);
|
].map(p => `${site}${p}`);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@ const txtFiles = getTxtFiles();
|
||||||
|
|
||||||
<details open>
|
<details open>
|
||||||
<summary>txt</summary>
|
<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>
|
</details>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"installCommand": "../install.sh",
|
"installCommand": "../install.sh",
|
||||||
"buildCommand": "pnpm --filter @ily/www build",
|
"buildCommand": "pnpm --filter @ily/www build",
|
||||||
"outputDirectory": "dist"
|
"outputDirectory": "dist",
|
||||||
|
"redirects": [
|
||||||
|
{ "source": "/txt/now.txt", "destination": "/now.txt", "permanent": true }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue