article update automation #4
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user