feat: git clone if articles does not exist

This commit is contained in:
Keisuke Hirata 2024-09-03 21:34:56 +09:00
parent 8b599165e1
commit 11210336cd

View File

@ -9,6 +9,10 @@ export default async function init(db: Postgres) {
console.log('Pulling articles from git..'); console.log('Pulling articles from git..');
const stdout = execSync('git -c core.sshCommand="ssh -i ../key -F /dev/null" pull', { cwd: './articles/' }); const stdout = execSync('git -c core.sshCommand="ssh -i ../key -F /dev/null" pull', { cwd: './articles/' });
console.log(stdout.toString()); console.log(stdout.toString());
} else {
console.log('Cloning articles from git..');
const stdout = execSync('git -c core.sshCommand="ssh -i ./key -F /dev/null" clone git@gitea.hareworks.net:Hare/blog-articles.git articles', { cwd: './' });
console.log(stdout.toString());
} }
const schemas = [ const schemas = [
@ -113,7 +117,13 @@ export default async function init(db: Postgres) {
for (const { path, id } of articleFiles) { for (const { path, id } of articleFiles) {
const res = await db.query('select * from article where id = $1', [id]); const res = await db.query('select * from article where id = $1', [id]);
const compiled = await compile(fs.readFileSync(path, 'utf-8')); const compiled = await compile(fs.readFileSync(path, 'utf-8'), {
highlight: {
highlighter: (code: string, lang: string) => {
return `<Codeblock><code class="language-${lang}">${code}</code></Codeblock>`;
}
}
});
const title = compiled.data.fm.title; const title = compiled.data.fm.title;
const category = path.split('/')[3]; const category = path.split('/')[3];