Compare commits

...

2 Commits

4 changed files with 32 additions and 10 deletions

View File

@ -110,7 +110,7 @@ database.
If you don't want the astro integration, change the switch in `options.ts` to `false`.
```json
```typescript
{
settings: {
comments: {

13
package-lock.json generated
View File

@ -19,6 +19,7 @@
"luxon": "^3.5.0",
"marked": "^15.0.2",
"pg": "^8.13.1",
"pinyin-pro": "^3.26.0",
"qrcode-svg": "^1.1.0",
"sharp": "^0.33.5",
"ultrahtml": "^1.5.3"
@ -3890,9 +3891,9 @@
"license": "MIT"
},
"node_modules/electron-to-chromium": {
"version": "1.5.66",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.66.tgz",
"integrity": "sha512-pI2QF6+i+zjPbqRzJwkMvtvkdI7MjVbSh2g8dlMguDJIXEPw+kwasS1Jl+YGPEBfGVxsVgGUratAKymPdPo2vQ==",
"version": "1.5.67",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.67.tgz",
"integrity": "sha512-nz88NNBsD7kQSAGGJyp8hS6xSPtWwqNogA0mjtc2nUYeEf3nURK9qpV18TuBdDmEDgVWotS8Wkzf+V52dSQ/LQ==",
"license": "ISC"
},
"node_modules/emmet": {
@ -7146,6 +7147,12 @@
"node": ">=6"
}
},
"node_modules/pinyin-pro": {
"version": "3.26.0",
"resolved": "https://registry.npmjs.org/pinyin-pro/-/pinyin-pro-3.26.0.tgz",
"integrity": "sha512-HcBZZb0pvm0/JkPhZHWA5Hqp2cWHXrrW/WrV+OtaYYM+kf35ffvZppIUuGmyuQ7gDr1JDJKMkbEE+GN0wfMoGg==",
"license": "MIT"
},
"node_modules/pkg-dir": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz",

View File

@ -52,6 +52,7 @@
"luxon": "^3.5.0",
"marked": "^15.0.2",
"pg": "^8.13.1",
"pinyin-pro": "^3.26.0",
"qrcode-svg": "^1.1.0",
"sharp": "^0.33.5",
"ultrahtml": "^1.5.3"

View File

@ -1,6 +1,7 @@
import { defaultCover } from '@/content/config.ts';
import options from '@/options';
import { getCollection, getEntry, type Render } from 'astro:content';
import { pinyin } from 'pinyin-pro';
// Import the collections from the astro content.
const categoriesCollection = await getCollection('categories');
@ -61,11 +62,13 @@ export const categories: Category[] = categoriesCollection.map((cat) => ({
permalink: `/cats/${cat.data.slug}`,
...cat.data,
}));
export const tags: Tag[] = tagsCollection[0].data.map((tag) => ({
counts: posts.filter((post) => post.tags.includes(tag.name)).length,
permalink: `/tags/${tag.slug}`,
...tag,
}));
export const tags: Tag[] = tagsCollection.flatMap((tags) => {
return tags.data.map((tag) => ({
counts: posts.filter((post) => post.tags.includes(tag.name)).length,
permalink: `/tags/${tag.slug}`,
...tag,
}));
});
// Find the missing categories from posts.
const missingCategories: string[] = posts
@ -78,7 +81,18 @@ if (missingCategories.length > 0) {
// Find the missing tags from posts.
const missingTags: string[] = posts.flatMap((post) => post.tags).filter((tag) => !tags.find((t) => t.name === tag));
if (missingTags.length > 0) {
throw new Error(`The bellowing tags has not been configured:\n$${missingTags.join('\n')}`);
console.warn(`The bellowing tags has not been configured:\n${missingTags.join('\n')}`);
for (const missingTag of missingTags) {
const slug = pinyin(missingTag, { toneType: 'none', separator: '-', nonZh: 'consecutive', type: 'string' })
.replaceAll(' ', '-')
.toLowerCase();
tags.push({
name: missingTag,
slug: slug,
permalink: `/tags/${slug}`,
counts: posts.filter((post) => post.tags.includes(missingTag)).length,
});
}
}
// Find the missing covers from posts.