Compare commits

..

No commits in common. "19d63ed0d5009b143e231877d9a02e1062cfc1a0" and "41674ea6a175c8917f8e793506638a81ee50d606" have entirely different histories.

9 changed files with 22 additions and 34 deletions

3
.gitmodules vendored
View File

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

View File

@ -3,7 +3,6 @@
--color-concept: hsl(39, 100%, 25%, 0.5);
--color-concept-hsl: 39, 100%, 25%;
--color-outline: #ffffff40;
width: 100%;
* {
color: var(--color-text);
}
@ -11,15 +10,10 @@
position: relative;
width: auto;
font-size: 2rem;
margin-bottom: 0.5rem;
border-bottom: 1px solid var(--color-outline);
padding-bottom: 0.5rem;
}
hr {
padding: 0;
margin: 0;
border: none;
border-top: 1px solid var(--color-outline);
}
> *:not(h1, hr) {
> *:not(h1) {
margin-left: 2rem;
}
h2 {
@ -99,7 +93,6 @@
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 isUpdated}
{#if data.updated_at}
<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 isUpdated}<br />
{#if data.updated_at}<br />
updated <FormattedDate date={data.updated_at} />
{/if}
</span>
@ -100,7 +100,7 @@
min-height: 100%;
padding: 20px;
padding-top: 100px;
max-width: 1000px;
width: 1000px;
margin: 0 auto;
display: flex;
flex-direction: column;

View File

@ -1,4 +1,5 @@
import pg from 'pg';
import { getConnection } from './database/get_connection';
export class Postgres {
client: pg.PoolClient | null = null;
@ -32,3 +33,7 @@ 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,7 +13,3 @@ 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,10 +9,6 @@ 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 = [
@ -117,19 +113,13 @@ 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'), {
highlight: {
highlighter: (code: string, lang: string) => {
return `<Codeblock><code class="language-${lang}">${code}</code></Codeblock>`;
}
}
});
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;
const released_at = new Date(compiled.data.fm.released_at);
const updated_at = (compiled.data.fm.updated_at !== null) ? new Date(compiled.data.fm.updated_at) : released_at;
const updated_at = new Date(compiled.data.fm.updated_at);
const image = compiled.data.fm.image;
const publish = compiled.data.fm.publish;
const content = compiled.code

View File

@ -7,16 +7,17 @@ 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, locals }) => {
export const POST: RequestHandler = async ({ url }) => {
const token = url.searchParams.get('token');
console.log(token);
if (token !== TOKEN) {
return error(401, 'Unauthorized');
}
await init(await PG(locals.db));
await init(await PG(getConnection()));
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(404, 'Not found');
error(500, (e as Error).message);
} 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(404, 'Not found');
error(500, (e as Error).message);
} finally {
await db.release();
}