style tweaks #8

Merged
Hare merged 8 commits from develop into master 2024-09-03 21:37:03 +09:00
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%, 0.5);
--color-concept-hsl: 39, 100%, 25%; --color-concept-hsl: 39, 100%, 25%;
--color-outline: #ffffff40; --color-outline: #ffffff40;
width: 100%;
* { * {
color: var(--color-text); color: var(--color-text);
} }
@ -10,10 +11,15 @@
position: relative; position: relative;
width: auto; width: auto;
font-size: 2rem; font-size: 2rem;
border-bottom: 1px solid var(--color-outline); margin-bottom: 0.5rem;
padding-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; margin-left: 2rem;
} }
h2 { h2 {
@ -93,6 +99,7 @@
font-family: monospace; font-family: monospace;
margin-top: 0.75rem; margin-top: 0.75rem;
margin-bottom: 0.75rem; margin-bottom: 0.75rem;
white-space: pre-wrap;
} }
code { code {
display: inline-block; display: inline-block;

View File

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

View File

@ -1,5 +1,4 @@
import pg from 'pg'; import pg from 'pg';
import { getConnection } from './database/get_connection';
export class Postgres { export class Postgres {
client: pg.PoolClient | null = null; client: pg.PoolClient | null = null;
@ -33,7 +32,3 @@ export class Postgres {
export default async ( export default async (
pool: pg.Pool pool: pg.Pool
) => { return await Postgres.new(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 }); const pool = new Pool({ connectionString });
export const getConnection = () => pool; 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..'); 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,13 +117,19 @@ 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];
const tags: string[] = compiled.data.fm.tags; const tags: string[] = compiled.data.fm.tags;
const released_at = new Date(compiled.data.fm.released_at); 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 image = compiled.data.fm.image;
const publish = compiled.data.fm.publish; const publish = compiled.data.fm.publish;
const content = compiled.code const content = compiled.code

View File

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

View File

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

View File

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