Compare commits
19
Commits
e389a3d2f9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
912e1c46d9 | ||
|
|
3e32df5761 | ||
|
|
992c99d2fb | ||
|
|
5c05db4580 | ||
|
|
bafa8e4d18 | ||
|
|
b529e96a6b | ||
|
|
7f395bcfaa | ||
|
|
97600ed402 | ||
|
|
ae48a85ece | ||
|
|
9f162e83c4 | ||
|
|
e4548bf10b | ||
|
|
5b441ff0cf | ||
|
|
76bd2a5e1b | ||
|
|
e3a83ee561 | ||
|
|
dd057dd335 | ||
|
|
f11bdf15fc | ||
|
|
5ec1839ec7 | ||
|
|
2fdcc1633d | ||
|
|
6173dffba3 |
@@ -1,6 +1,6 @@
|
|||||||
# blog.hareworks.net
|
# blog.hareworks.net
|
||||||
|
|
||||||
<img src="https://blog.hareworks.net/img/logo.png" width="200">
|
<img src="./static/img/logo.png" width="200">
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
|
|||||||
+11
-6
@@ -1,19 +1,24 @@
|
|||||||
# For Build
|
# For Build
|
||||||
FROM node:22-slim as builder
|
FROM node:22-slim AS base
|
||||||
|
|
||||||
|
ENV PNPM_HOME="/pnpm"
|
||||||
|
ENV PATH="$PNPM_HOME:$PATH"
|
||||||
|
RUN corepack enable
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
COPY package-lock.json ./
|
COPY pnpm-lock.yaml ./
|
||||||
COPY tsconfig.json ./
|
COPY tsconfig.json ./
|
||||||
RUN npm ci
|
|
||||||
|
FROM base AS builder
|
||||||
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# For Run
|
FROM base
|
||||||
FROM node:22-slim
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
Generated
-4149
File diff suppressed because it is too large
Load Diff
+25
-23
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "blog.hareworks.net",
|
"name": "blog.hareworks.net",
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
@@ -13,32 +13,34 @@
|
|||||||
"format": "prettier --write ."
|
"format": "prettier --write ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.28.1",
|
"@playwright/test": "^1.49.1",
|
||||||
"@sveltejs/adapter-auto": "^3.0.0",
|
"@sveltejs/adapter-auto": "^3.3.1",
|
||||||
"@sveltejs/adapter-node": "^5.2.2",
|
"@sveltejs/adapter-node": "^5.2.10",
|
||||||
"@sveltejs/kit": "^2.0.0",
|
"@sveltejs/kit": "^2.12.1",
|
||||||
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
|
"@sveltejs/vite-plugin-svelte": "^5.0.2",
|
||||||
"@types/eslint": "^9.6.0",
|
"@types/eslint": "^9.6.1",
|
||||||
"@types/pg": "^8.11.6",
|
"@types/pg": "^8.11.10",
|
||||||
"eslint": "^9.0.0",
|
"eslint": "^9.17.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
"eslint-plugin-svelte": "^2.36.0",
|
"eslint-plugin-svelte": "^2.46.1",
|
||||||
"globals": "^15.0.0",
|
"globals": "^15.13.0",
|
||||||
"prettier": "^3.1.1",
|
"prettier": "^3.4.2",
|
||||||
"prettier-plugin-svelte": "^3.1.2",
|
"prettier-plugin-svelte": "^3.3.2",
|
||||||
"shiki": "^1.16.2",
|
"shiki": "^1.24.2",
|
||||||
"svelte": "^5.0.0-next.1",
|
"svelte": "^5.14.1",
|
||||||
"svelte-check": "^3.6.0",
|
"svelte-check": "4.1.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.7.2",
|
||||||
"typescript-eslint": "^8.0.0",
|
"typescript-eslint": "^8.18.1",
|
||||||
"vite": "^5.0.3"
|
"vite": "^6.0.3"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.7",
|
||||||
"mdsvex": "^0.12.3",
|
"mdsvex": "^0.12.3",
|
||||||
"pg": "^8.12.0",
|
"pg": "^8.13.1",
|
||||||
"sass": "^1.77.8",
|
"rehype-autolink-headings": "^7.1.0",
|
||||||
"simple-git": "^3.26.0"
|
"rehype-slug": "^6.0.0",
|
||||||
|
"sass": "^1.83.0",
|
||||||
|
"simple-git": "^3.27.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+3127
File diff suppressed because it is too large
Load Diff
Vendored
+5
-3
@@ -1,13 +1,15 @@
|
|||||||
// See https://kit.svelte.dev/docs/types#app
|
// See https://kit.svelte.dev/docs/types#app
|
||||||
// for information about these interfaces
|
// for information about these interfaces
|
||||||
import { Database } from 'pg';
|
import { Pool } from "pg";
|
||||||
|
import type { SimpleGit } from "simple-git";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace App {
|
namespace App {
|
||||||
// interface Error {}
|
// interface Error {}
|
||||||
interface Locals {
|
interface Locals {
|
||||||
db: any;
|
db: Pool;
|
||||||
}
|
git: SimpleGit;
|
||||||
|
}
|
||||||
// interface PageData {}
|
// interface PageData {}
|
||||||
// interface PageState {}
|
// interface PageState {}
|
||||||
// interface Platform {}
|
// interface Platform {}
|
||||||
|
|||||||
+4
-2
@@ -1,9 +1,11 @@
|
|||||||
import type { Handle } from '@sveltejs/kit'
|
import type { Handle } from '@sveltejs/kit'
|
||||||
import { getConnection } from '$lib/server/database/get_connection'
|
import { getPool } from '$lib/server/database/pool';
|
||||||
|
import git from '$lib/server/git';
|
||||||
|
|
||||||
export const handle: Handle = async ({ event, resolve }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
const pg = getConnection();
|
const pg = getPool;
|
||||||
event.locals.db = pg;
|
event.locals.db = pg;
|
||||||
|
event.locals.git = git;
|
||||||
|
|
||||||
const result = await resolve(event);
|
const result = await resolve(event);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
@import './ress.css';
|
@forward './ress.css';
|
||||||
@import '../variables.scss';
|
@forward '../variables.scss';
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'ZenKakuGothicNew-Regular';
|
font-family: 'ZenKakuGothicNew-Regular';
|
||||||
|
|||||||
+36
-3
@@ -7,15 +7,16 @@
|
|||||||
|
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
|
|
||||||
padding-left: 2rem;
|
padding-left: 0rem;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: auto;
|
width: auto;
|
||||||
font-size: 1.8rem;
|
font-size: 1.8rem;
|
||||||
margin-bottom: 0.5rem;
|
padding: 1.5rem 0 0.25rem 0;
|
||||||
margin-left: -1rem;
|
margin: 0 0 0.75rem 0rem;
|
||||||
|
border-bottom: 1px solid var(--color-outline);
|
||||||
}
|
}
|
||||||
|
|
||||||
hr {
|
hr {
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
|
padding: 1rem 0 0.25rem 0;
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
@@ -71,6 +73,37 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul,
|
||||||
|
ol {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
position: relative;
|
||||||
|
padding-left: 1rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
&::before {
|
||||||
|
content: '•';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
color: var(--color-concept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ul > li {
|
||||||
|
&::before {
|
||||||
|
content: '•';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ol > li {
|
||||||
|
counter-increment: item;
|
||||||
|
&::before {
|
||||||
|
content: counter(item) '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
blockquote {
|
blockquote {
|
||||||
position: relative;
|
position: relative;
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let html: string;
|
||||||
|
|
||||||
|
const headings: {
|
||||||
|
level: number;
|
||||||
|
id: string;
|
||||||
|
text: string;
|
||||||
|
}[] = [];
|
||||||
|
html.match(/<h(\d) id="([^"]+)">([^<]+)<\/h\d>/g)?.forEach((match) => {
|
||||||
|
console.log(match);
|
||||||
|
const [, level, id, text] = match.match(/<h(\d) id="([^"]+)">([^<]+)<\/h\d>/)!;
|
||||||
|
headings.push({ level: +level, id, text });
|
||||||
|
});
|
||||||
|
let output = '';
|
||||||
|
let lastLevel = 1;
|
||||||
|
headings.forEach(({ level, id, text }) => {
|
||||||
|
console.log(level, id, text);
|
||||||
|
if (level > lastLevel) {
|
||||||
|
output += '<ul>';
|
||||||
|
} else if (level < lastLevel) {
|
||||||
|
output += '</li></ul>'.repeat(lastLevel - level);
|
||||||
|
} else {
|
||||||
|
if (output !== '') {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output += `<li><a href="#${id}">${text}</a>`;
|
||||||
|
lastLevel = level;
|
||||||
|
});
|
||||||
|
output += '</li>'.repeat(lastLevel);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="overview">
|
||||||
|
<ul>
|
||||||
|
{@html output}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.overview {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
:global(ul) {
|
||||||
|
list-style-type: none;
|
||||||
|
margin-left: 0.5em;
|
||||||
|
padding-left: 0.25em;
|
||||||
|
border-left: 1px solid var(--line-primary);
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
ul {
|
||||||
|
border-left: none;
|
||||||
|
}
|
||||||
|
:global(li) {
|
||||||
|
padding: 0.5em 0.5em 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
:global(a) {
|
||||||
|
text-decoration: none;
|
||||||
|
color: var(--text-primary);
|
||||||
|
padding: 0.15em 0.4em;
|
||||||
|
border-radius: 0.25em;
|
||||||
|
text-wrap: nowrap;
|
||||||
|
box-sizing: border-box;
|
||||||
|
&:hover {
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
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 Overview from '$lib/components/overview.svelte';
|
||||||
|
|
||||||
import type { Article } from '$lib/article';
|
import type { Article } from '$lib/article';
|
||||||
export let data: Article;
|
export let data: Article;
|
||||||
@@ -32,39 +33,46 @@
|
|||||||
</div> -->
|
</div> -->
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<main>
|
<main>
|
||||||
<div class="title">
|
<div class="content">
|
||||||
<h1>{data.title}</h1>
|
<div class="title">
|
||||||
<div class="meta">
|
<h1>{data.title}</h1>
|
||||||
<div class="left">
|
<div class="meta">
|
||||||
<span>
|
<div class="left">
|
||||||
released <FormattedDate date={data.released_at} />
|
<span>
|
||||||
{#if isUpdated}<br />
|
released <FormattedDate date={data.released_at} />
|
||||||
updated <FormattedDate date={data.updated_at} />
|
{#if isUpdated}<br />
|
||||||
{/if}
|
updated <FormattedDate date={data.updated_at} />
|
||||||
</span>
|
{/if}
|
||||||
<span>
|
</span>
|
||||||
<a href="/category/{data.category}"
|
<span>
|
||||||
>{data.category[0].toUpperCase() + data.category.slice(1)}</a
|
<a href="/category/{data.category}"
|
||||||
>
|
>{data.category[0].toUpperCase() + data.category.slice(1)}</a
|
||||||
{#each data.tags as tag}
|
>
|
||||||
<a href={`/search?tag=${tag}`}>{tag}</a>
|
{#each data.tags as tag}
|
||||||
{/each}
|
<a href={`/search?tag=${tag}`}>{tag}</a>
|
||||||
</span>
|
{/each}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="right">
|
||||||
|
<img
|
||||||
|
src="https://gitea.hareworks.net/avatars/e595ec10f8052671deab92caca78220fc838f63259bcd542a0d93f53e2371d52?size=512"
|
||||||
|
alt="Author"
|
||||||
|
/>
|
||||||
|
<div>@{data.author}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
</div>
|
||||||
<img
|
<div class="panel">
|
||||||
src="https://gitea.hareworks.net/avatars/e595ec10f8052671deab92caca78220fc838f63259bcd542a0d93f53e2371d52?size=512"
|
<div class="document">
|
||||||
alt="Author"
|
<slot />
|
||||||
/>
|
|
||||||
<div>@{data.author}</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel">
|
<div class="card-container">
|
||||||
<div class="document">
|
<div class="card">
|
||||||
<slot />
|
<Overview html={data.content} />
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
@@ -100,30 +108,47 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
.card {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
}
|
|
||||||
main {
|
main {
|
||||||
border: 1px solid var(--line-primary);
|
|
||||||
border-top: none;
|
|
||||||
border-bottom: none;
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
color: white;
|
color: white;
|
||||||
min-height: 100%;
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: start;
|
||||||
|
.content {
|
||||||
|
border: 1px solid var(--line-primary);
|
||||||
|
border-top: none;
|
||||||
|
border-bottom: none;
|
||||||
|
min-height: 100%;
|
||||||
|
padding: 100px 100px 0 100px;
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-container {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
background-color: var(--background-primary);
|
||||||
|
box-sizing: border-box;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
padding-top: 100px;
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 0 auto;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
overflow: visible;
|
||||||
|
.card {
|
||||||
|
width: 100px;
|
||||||
|
padding: 0.5em 0;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 0;
|
margin: 0 -30px 0 -30px;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
|
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
import { compile, escapeSvelte } from "mdsvex";
|
import { compile, escapeSvelte } from "mdsvex";
|
||||||
import { createHighlighter } from "shiki";
|
import { createHighlighter } from "shiki";
|
||||||
import { kanagawa_dark as theme } from "$lib/kanagawa"
|
import { kanagawa_dark as theme } from "$lib/kanagawa"
|
||||||
|
import rehypeAutolinkHeadings from "rehype-autolink-headings";
|
||||||
|
import rehypeSlug from "rehype-slug";
|
||||||
|
|
||||||
const highlighter = await createHighlighter({
|
const highlighter = await createHighlighter({
|
||||||
themes: [theme],
|
themes: [theme],
|
||||||
@@ -19,5 +20,6 @@ export default async function compileArticle(code: string) {
|
|||||||
return html;
|
return html;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
rehypePlugins: [rehypeAutolinkHeadings, rehypeSlug],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,90 +1,22 @@
|
|||||||
// initialize
|
import type { Postgres } from '$lib/server/database/postgres';
|
||||||
import type { Postgres } from '$lib/server/database';
|
import { type SimpleGit, CheckRepoActions } from 'simple-git';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import compile from '$lib/server/article';
|
import compileArticle from '$lib/server/article_compiler';
|
||||||
import article_git from '$lib/server/aritcle-git';
|
import type { TableSchema } from '$lib/server/database/table';
|
||||||
|
import server_table from '$lib/server/database/table';
|
||||||
import { format } from '$lib/scripts/formatted_date';
|
import { format } from '$lib/scripts/formatted_date';
|
||||||
|
|
||||||
export default async function init(db: Postgres) {
|
const load = async (db: Postgres, git: SimpleGit) => {
|
||||||
await cloneRepo();
|
|
||||||
await createTable(db, [
|
|
||||||
{
|
|
||||||
name: 'article',
|
|
||||||
columns: [
|
|
||||||
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
|
||||||
{ name: 'id', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'released_at', type: 'timestamp', constraint: 'not null' },
|
|
||||||
{ name: 'updated_at', type: 'timestamp', constraint: 'not null' },
|
|
||||||
{ name: 'author', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'email', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'title', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'category', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'tags', type: 'text[]', constraint: 'not null' },
|
|
||||||
{ name: 'image', type: 'text', constraint: '' },
|
|
||||||
{ name: 'publish', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'content', type: 'text', constraint: 'not null' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'article_comment',
|
|
||||||
columns: [
|
|
||||||
{ name: 'id', type: 'serial', constraint: 'primary key' },
|
|
||||||
{ name: 'article', type: 'integer', constraint: 'not null' },
|
|
||||||
{ name: 'posted_at', type: 'timestamp', constraint: 'not null' },
|
|
||||||
{ name: 'content', type: 'text', constraint: 'not null' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'thread',
|
|
||||||
columns: [
|
|
||||||
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
|
||||||
{ name: 'id', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'title', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'category', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'created_at', type: 'timestamp', constraint: 'not null' },
|
|
||||||
{ name: 'updated_at', type: 'timestamp', constraint: 'not null' },
|
|
||||||
{ name: 'tags', type: 'text[]', constraint: 'not null' },
|
|
||||||
{ name: 'content', type: 'text', constraint: 'not null' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'thread_post',
|
|
||||||
columns: [
|
|
||||||
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
|
||||||
{ name: 'thread_id', type: 'integer', constraint: 'not null' },
|
|
||||||
{ name: 'title', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'posted_at', type: 'timestamp', constraint: 'not null' },
|
|
||||||
{ name: 'content', type: 'text', constraint: 'not null' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'thread_comment',
|
|
||||||
columns: [
|
|
||||||
{ name: 'id', type: 'serial', constraint: 'primary key' },
|
|
||||||
{ name: 'thread', type: 'integer', constraint: 'not null' },
|
|
||||||
{ name: 'posted_at', type: 'timestamp', constraint: 'not null' },
|
|
||||||
{ name: 'content', type: 'text', constraint: 'not null' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'tag',
|
|
||||||
columns: [
|
|
||||||
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
|
||||||
{ name: 'name', type: 'text', constraint: 'not null' },
|
|
||||||
{ name: 'ref_count', type: 'integer', constraint: 'not null' },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
|
|
||||||
const articleFiles = await crawlArticles(db);
|
const articleFiles = await crawlArticles(db);
|
||||||
await db.query('update tag set ref_count = 0');
|
await db.query('update tag set ref_count = 0');
|
||||||
|
|
||||||
|
await db.begin();
|
||||||
|
let i = 0;
|
||||||
for (const { path, id } of articleFiles) {
|
for (const { path, id } of articleFiles) {
|
||||||
|
await db.savepoint(`load${i}`);
|
||||||
console.log(`Processing ${id}...`);
|
console.log(`Processing ${id}...`);
|
||||||
await db.begin();
|
|
||||||
try {
|
try {
|
||||||
const gitlog = await article_git.log({
|
const gitlog = await git.log({
|
||||||
file: path.slice(11),
|
file: path.slice(11),
|
||||||
strictDate: true,
|
strictDate: true,
|
||||||
});
|
});
|
||||||
@@ -101,7 +33,7 @@ export default async function init(db: Postgres) {
|
|||||||
console.log(`Author: ${author} <${email}>\nReleased at: ${format(released_at)}\nUpdated at: ${format(updated_at)}`);
|
console.log(`Author: ${author} <${email}>\nReleased at: ${format(released_at)}\nUpdated at: ${format(updated_at)}`);
|
||||||
|
|
||||||
const category = path.split('/')[3];
|
const category = path.split('/')[3];
|
||||||
const compiled = await compile(fs.readFileSync(path, 'utf-8'));
|
const compiled = await compileArticle(fs.readFileSync(path, 'utf-8'));
|
||||||
const title = compiled.data.fm.title;
|
const title = compiled.data.fm.title;
|
||||||
const tags: string[] = compiled.data.fm.tags;
|
const tags: string[] = compiled.data.fm.tags;
|
||||||
const image = compiled.data.fm.image;
|
const image = compiled.data.fm.image;
|
||||||
@@ -135,36 +67,29 @@ export default async function init(db: Postgres) {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
await db.rollback();
|
await db.rollbackTo(`load${i}`);
|
||||||
} finally {
|
} finally {
|
||||||
console.log('');
|
console.log('');
|
||||||
await db.commit();
|
await db.releaseSavepoint(`load${i}`);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await db.commit();
|
||||||
await db.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArticleFileItem = {
|
type ArticleFileItem = {
|
||||||
path: string,
|
path: string,
|
||||||
id: string,
|
id: string,
|
||||||
}
|
}
|
||||||
export type TableSchema = {
|
|
||||||
name: string,
|
|
||||||
columns: {
|
|
||||||
name: string,
|
|
||||||
type: string,
|
|
||||||
constraint: string,
|
|
||||||
}[],
|
|
||||||
}
|
|
||||||
|
|
||||||
const cloneRepo = async () => {
|
const cloneRepo = async (git: SimpleGit) => {
|
||||||
if (fs.existsSync('./articles/')) {
|
const isRepoRoot = await git.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);
|
||||||
|
if (isRepoRoot) {
|
||||||
console.log('Pulling articles from git..');
|
console.log('Pulling articles from git..');
|
||||||
await article_git.pull();
|
await git.pull();
|
||||||
} else {
|
} else {
|
||||||
console.log('Cloning articles from git..');
|
console.log('Cloning articles from git..');
|
||||||
await article_git.clone('git@gitea.hareworks.net:Hare/blog-articles.git', 'articles');
|
await git.clone('git@gitea.hareworks.net:Hare/blog-articles.git', './');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,3 +131,14 @@ const crawlArticles = async (db: Postgres): Promise<ArticleFileItem[]> => {
|
|||||||
scanDir('./articles/article');
|
scanDir('./articles/article');
|
||||||
return articleFiles;
|
return articleFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function init(db: Postgres, git: SimpleGit) {
|
||||||
|
await createTable(db, server_table);
|
||||||
|
await cloneRepo(git);
|
||||||
|
await load(db, git);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function reload(db: Postgres, git: SimpleGit) {
|
||||||
|
await cloneRepo(git);
|
||||||
|
await load(db, git);
|
||||||
|
}
|
||||||
@@ -12,12 +12,13 @@ const connectionString = `postgres://${PG_USER}:${PG_PASS}@${PG_HOST}:${PG_PORT}
|
|||||||
|
|
||||||
let pool = new Pool({ connectionString });
|
let pool = new Pool({ connectionString });
|
||||||
|
|
||||||
export const getConnection = () => pool;
|
export const getPool = pool;
|
||||||
|
|
||||||
export const reConnect = async () => {
|
export const reConnect = async () => {
|
||||||
pool = new Pool({ connectionString });
|
pool = new Pool({ connectionString });
|
||||||
}
|
}
|
||||||
|
|
||||||
import init_db from '$lib/server/database/init';
|
import { init as init_data} from '$lib/server/data_loader';
|
||||||
import PG from '$lib/server/database';
|
import PG from '$lib/server/database/postgres';
|
||||||
await init_db(await PG(pool));
|
import git from '$lib/server/git';
|
||||||
|
await init_data(await PG(pool), git);
|
||||||
@@ -24,9 +24,21 @@ export class Postgres {
|
|||||||
await this.client!.query('commit');
|
await this.client!.query('commit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async savepoint(name: string) {
|
||||||
|
await this.client!.query(`savepoint ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
async rollback() {
|
async rollback() {
|
||||||
await this.client!.query('rollback');
|
await this.client!.query('rollback');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async rollbackTo(name: string) {
|
||||||
|
await this.client!.query(`rollback to ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async releaseSavepoint(name: string) {
|
||||||
|
await this.client!.query(`release savepoint ${name}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
export type TableSchema = {
|
||||||
|
name: string,
|
||||||
|
columns: {
|
||||||
|
name: string,
|
||||||
|
type: string,
|
||||||
|
constraint: string,
|
||||||
|
}[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
name: 'article',
|
||||||
|
columns: [
|
||||||
|
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
||||||
|
{ name: 'id', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'released_at', type: 'timestamp', constraint: 'not null' },
|
||||||
|
{ name: 'updated_at', type: 'timestamp', constraint: 'not null' },
|
||||||
|
{ name: 'author', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'email', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'title', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'category', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'tags', type: 'text[]', constraint: 'not null' },
|
||||||
|
{ name: 'image', type: 'text', constraint: '' },
|
||||||
|
{ name: 'publish', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'content', type: 'text', constraint: 'not null' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'article_comment',
|
||||||
|
columns: [
|
||||||
|
{ name: 'id', type: 'serial', constraint: 'primary key' },
|
||||||
|
{ name: 'article', type: 'integer', constraint: 'not null' },
|
||||||
|
{ name: 'posted_at', type: 'timestamp', constraint: 'not null' },
|
||||||
|
{ name: 'content', type: 'text', constraint: 'not null' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'thread',
|
||||||
|
columns: [
|
||||||
|
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
||||||
|
{ name: 'id', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'title', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'category', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'created_at', type: 'timestamp', constraint: 'not null' },
|
||||||
|
{ name: 'updated_at', type: 'timestamp', constraint: 'not null' },
|
||||||
|
{ name: 'tags', type: 'text[]', constraint: 'not null' },
|
||||||
|
{ name: 'content', type: 'text', constraint: 'not null' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'thread_post',
|
||||||
|
columns: [
|
||||||
|
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
||||||
|
{ name: 'thread_id', type: 'integer', constraint: 'not null' },
|
||||||
|
{ name: 'title', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'posted_at', type: 'timestamp', constraint: 'not null' },
|
||||||
|
{ name: 'content', type: 'text', constraint: 'not null' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'thread_comment',
|
||||||
|
columns: [
|
||||||
|
{ name: 'id', type: 'serial', constraint: 'primary key' },
|
||||||
|
{ name: 'thread', type: 'integer', constraint: 'not null' },
|
||||||
|
{ name: 'posted_at', type: 'timestamp', constraint: 'not null' },
|
||||||
|
{ name: 'content', type: 'text', constraint: 'not null' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'tag',
|
||||||
|
columns: [
|
||||||
|
{ name: 'seq', type: 'serial', constraint: 'primary key' },
|
||||||
|
{ name: 'name', type: 'text', constraint: 'not null' },
|
||||||
|
{ name: 'ref_count', type: 'integer', constraint: 'not null' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
] as TableSchema[];
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
|
import fs from 'fs';
|
||||||
import { simpleGit, } from 'simple-git';
|
import { simpleGit, } from 'simple-git';
|
||||||
import type { SimpleGit, SimpleGitOptions } from 'simple-git';
|
import type { SimpleGit, SimpleGitOptions } from 'simple-git';
|
||||||
|
|
||||||
console.log(process.cwd()+'/articles');
|
console.log(process.cwd()+'/articles');
|
||||||
|
fs.mkdirSync(process.cwd()+'/articles', { recursive: true });
|
||||||
export const gitOptions: Partial<SimpleGitOptions> = {
|
export const gitOptions: Partial<SimpleGitOptions> = {
|
||||||
baseDir: process.cwd()+'/articles',
|
baseDir: process.cwd()+'/articles',
|
||||||
binary: 'git',
|
binary: 'git',
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import PG from '$lib/server/database';
|
import PG from '$lib/server/database/postgres';
|
||||||
import { format } from '$lib/scripts/formatted_date';
|
import { format } from '$lib/scripts/formatted_date';
|
||||||
|
|
||||||
let data: {
|
let data: {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import {
|
|||||||
TOKEN
|
TOKEN
|
||||||
} from '$env/static/private'
|
} from '$env/static/private'
|
||||||
|
|
||||||
import PG from '$lib/server/database';
|
import PG from '$lib/server/database/postgres';
|
||||||
// import { building } from '$app/environment';
|
import { building } from '$app/environment';
|
||||||
import init_db from '$lib/server/database/init';
|
import { reload as reload_data } from '$lib/server/data_loader';
|
||||||
|
|
||||||
export const POST: RequestHandler = async ({ url, locals }) => {
|
export const POST: RequestHandler = async ({ url, locals }) => {
|
||||||
const token = url.searchParams.get('token');
|
const token = url.searchParams.get('token');
|
||||||
@@ -17,6 +17,6 @@ export const POST: RequestHandler = async ({ url, locals }) => {
|
|||||||
return error(401, 'Unauthorized');
|
return error(401, 'Unauthorized');
|
||||||
}
|
}
|
||||||
|
|
||||||
await init_db(await PG(locals.db));
|
if (!building) await reload_data(await PG(locals.db), locals.git);
|
||||||
return new Response(String(token));
|
return new Response(String(token));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { json } from '@sveltejs/kit';
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async ({ url, locals }) => {
|
||||||
|
const category = String(url.searchParams.get('category'));
|
||||||
|
|
||||||
|
if (!category) {
|
||||||
|
error(400, 'Bad request');
|
||||||
|
}
|
||||||
|
|
||||||
|
const db = await locals.db;
|
||||||
|
const article = await db.query(
|
||||||
|
'SELECT * FROM article WHERE category = $1',
|
||||||
|
[category]
|
||||||
|
);
|
||||||
|
return new Response();
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Article } from '$lib/article';
|
import type { Article } from '$lib/article';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import PG from '$lib/server/database';
|
import PG from '$lib/server/database/postgres';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Article } from '$lib/article';
|
import type { Article } from '$lib/article';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import PG from '$lib/server/database';
|
import PG from '$lib/server/database/postgres';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
|
||||||
export function load() {
|
export function load() {
|
||||||
throw redirect(308, 'https://discord.gg/9RfkJeQQfB');
|
throw redirect(308, 'https://discord.gg/hbHzw7JkFq');
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 10 KiB |
@@ -3,14 +3,9 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
|
||||||
// for more information about preprocessors
|
|
||||||
preprocess: vitePreprocess(),
|
preprocess: vitePreprocess(),
|
||||||
|
|
||||||
kit: {
|
kit: {
|
||||||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
|
||||||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
|
||||||
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
|
||||||
adapter: adapter()
|
adapter: adapter()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user