Compare commits

..

9 Commits

9 changed files with 34 additions and 22 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "articles"]
path = articles
url = git@gitea.hareworks.net:Hare/blog-articles.git

View File

@ -3,6 +3,7 @@
--color-concept: hsl(39, 100%, 25%, 0.5);
--color-concept-hsl: 39, 100%, 25%;
--color-outline: #ffffff40;
width: 100%;
* {
color: var(--color-text);
}
@ -10,10 +11,15 @@
position: relative;
width: auto;
font-size: 2rem;
border-bottom: 1px solid var(--color-outline);
padding-bottom: 0.5rem;
margin-bottom: 0.5rem;
}
> *:not(h1) {
hr {
padding: 0;
margin: 0;
border: none;
border-top: 1px solid var(--color-outline);
}
> *:not(h1, hr) {
margin-left: 2rem;
}
h2 {
@ -93,6 +99,7 @@
font-family: monospace;
margin-top: 0.75rem;
margin-bottom: 0.75rem;
white-space: pre-wrap;
}
code {
display: inline-block;

View File

@ -5,10 +5,10 @@
import Footer from '$lib/components/footer.svelte';
import * as publish from '$lib/publish';
import FormattedDate from '$lib/components/formatted_date.svelte';
import Head from '$lib/components/head.svelte';
import type { Article } from '$lib/article';
export let data: Article;
const isUpdated = data.updated_at.getTime() != data.released_at.getTime();
</script>
<svelte:head>
@ -18,7 +18,7 @@
<meta property="og:image" content={data.image} />
<meta property="og:type" content="article" />
<meta property="article:published_time" content={data.released_at.toISOString()} />
{#if data.updated_at}
{#if isUpdated}
<meta property="article:modified_time" content={data.updated_at.toISOString()} />
{/if}
<meta property="article:author" content="HareWorks" />
@ -37,7 +37,7 @@
<div class="meta">
<span>
released <FormattedDate date={data.released_at} />
{#if data.updated_at}<br />
{#if isUpdated}<br />
updated <FormattedDate date={data.updated_at} />
{/if}
</span>
@ -100,7 +100,7 @@
min-height: 100%;
padding: 20px;
padding-top: 100px;
width: 1000px;
max-width: 1000px;
margin: 0 auto;
display: flex;
flex-direction: column;

View File

@ -1,5 +1,4 @@
import pg from 'pg';
import { getConnection } from './database/get_connection';
export class Postgres {
client: pg.PoolClient | null = null;
@ -33,7 +32,3 @@ export class Postgres {
export default async (
pool: pg.Pool
) => { return await Postgres.new(pool); };
import { building } from '$app/environment';
import init from '$lib/server/database/init_db';
if (!building) await init(await Postgres.new(getConnection()));

View File

@ -13,3 +13,7 @@ const connectionString = `postgres://${PG_USER}:${PG_PASS}@${PG_HOST}:${PG_PORT}
const pool = new Pool({ connectionString });
export const getConnection = () => pool;
import init from '$lib/server/database/init_db';
import PG from '$lib/server/database';
await init(await PG(pool));

View File

@ -9,6 +9,10 @@ export default async function init(db: Postgres) {
console.log('Pulling articles from git..');
const stdout = execSync('git -c core.sshCommand="ssh -i ../key -F /dev/null" pull', { cwd: './articles/' });
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 = [
@ -113,13 +117,19 @@ 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 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 category = path.split('/')[3];
const tags: string[] = compiled.data.fm.tags;
const released_at = new Date(compiled.data.fm.released_at);
const updated_at = new Date(compiled.data.fm.updated_at);
const updated_at = (compiled.data.fm.updated_at !== null) ? new Date(compiled.data.fm.updated_at) : released_at;
const image = compiled.data.fm.image;
const publish = compiled.data.fm.publish;
const content = compiled.code

View File

@ -7,17 +7,16 @@ import {
} from '$env/static/private'
import PG from '$lib/server/database';
import { getConnection } from '$lib/server/database/get_connection';
// import { building } from '$app/environment';
import init from '$lib/server/database/init_db';
export const POST: RequestHandler = async ({ url }) => {
export const POST: RequestHandler = async ({ url, locals }) => {
const token = url.searchParams.get('token');
console.log(token);
if (token !== TOKEN) {
return error(401, 'Unauthorized');
}
await init(await PG(getConnection()));
await init(await PG(locals.db));
return new Response(String(token));
};

View File

@ -22,7 +22,7 @@ export const load: PageServerLoad = async ({ params, locals }) => {
return data
} catch (e) {
await db.rollback();
error(500, (e as Error).message);
error(404, 'Not found');
} finally {
await db.release();
}

View File

@ -22,7 +22,7 @@ export const load: PageServerLoad = async ({ params, locals }) => {
return data
} catch (e) {
await db.rollback();
error(500, (e as Error).message);
error(404, 'Not found');
} finally {
await db.release();
}