diff --git a/src/lib/server/database/init_db.ts b/src/lib/server/database/init_db.ts index 1964187..cd090f8 100644 --- a/src/lib/server/database/init_db.ts +++ b/src/lib/server/database/init_db.ts @@ -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;