article update automation #4

Merged
Hare merged 7 commits from develop into master 2024-09-03 05:14:12 +09:00
Showing only changes of commit 0da14f3ebf - Show all commits

View File

@ -2,8 +2,15 @@
import type { Postgres } from '$lib/server/database';
import fs from 'fs';
import { compile } from 'mdsvex';
import { execSync } from 'child_process';
export default async function init(db: Postgres) {
// Create tables(when not exists)
if (fs.existsSync('./articles/')) {
console.log('Pulling articles from git..');
const stdout = execSync('git pull', { cwd: './articles/' });
console.log(stdout.toString());
}
const schemas = [
{
name: 'article',
@ -107,7 +114,7 @@ export default async function init(db: Postgres) {
for (const { path, id } of articleFiles) {
const res = await db.query('select * from article where id = $1', [id]);
const compiled = await compile(fs.readFileSync(path, 'utf-8'));
const title = compiled.data.fm.title;
const category = path.split('/')[3];
const tags: string[] = compiled.data.fm.tags;