Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 169f35b556 | |||
| 8d7388835b | |||
| 34c410b687 | |||
| af9b20485e |
@@ -1,5 +0,0 @@
|
||||
VITE_BASE_URL=http://localhost:8080/
|
||||
VITE_APP_TITLE=<i icon=rss></i> My Blog
|
||||
VITE_APP_SIGNATURE=By <b>me</b>
|
||||
VITE_APP_LANG=en
|
||||
VITE_CUSTOM_HEAD=
|
||||
@@ -3,7 +3,8 @@ on:
|
||||
schedule:
|
||||
- cron: "*/30 * * * *"
|
||||
push:
|
||||
|
||||
branches:
|
||||
- "main"
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
@@ -18,12 +19,6 @@ jobs:
|
||||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
- run: git clone ${{ vars.ARTICLES_REPOSITORY }} articles
|
||||
- run: bun run build
|
||||
env:
|
||||
VITE_BASE_URL: ${{ vars.VITE_BASE_URL }}
|
||||
VITE_APP_TITLE: ${{ vars.VITE_APP_TITLE }}
|
||||
VITE_APP_SIGNATURE: ${{ vars.VITE_APP_SIGNATURE }}
|
||||
VITE_APP_LANG: ${{ vars.VITE_APP_LANG }}
|
||||
VITE_CUSTOM_HEAD: ${{ vars.VITE_CUSTOM_HEAD }}
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: production-files
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
```bash
|
||||
git clone $REPOSITORY articles
|
||||
cp .env.example .env
|
||||
$EDITOR .env
|
||||
bun run build
|
||||
```
|
||||
|
||||
@@ -20,6 +18,12 @@ bun run build
|
||||
- [x] set page title
|
||||
- [x] SPA and opengraph
|
||||
- [x] build with github actions
|
||||
- [ ] proper docs
|
||||
- [ ] custom layout in sub repo ?
|
||||
- [ ] link to previous/next article
|
||||
- [x] config in sub repo
|
||||
- [x] copyright
|
||||
- [ ] nav bar on top
|
||||
- [ ] date updated
|
||||
- [ ] archive page
|
||||
- [ ] about page
|
||||
- [ ] contact/links
|
||||
- [ ] link to previous/next article
|
||||
- [ ] proper docs
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="/src/style.scss" />
|
||||
<meta property="og:url" content="%VITE_BASE_URL%" />
|
||||
<meta property="og:title" content="%VITE_APP_TITLE_NO_HTML%" />
|
||||
<link rel="alternate" href="%VITE_BASE_URL%/rss" type="application/rss+xml" title="RSS 2.0" />
|
||||
<link rel="alternate" href="%VITE_BASE_URL%/rss.xml" type="application/rss+xml" title="RSS 2.0" />
|
||||
<link rel="alternate" href="%VITE_BASE_URL%/atom.xml" type="application/atom+xml" title="Atom 2.0" />
|
||||
<link rel="alternate" href="%VITE_BASE_URL%/feed.json" type="application/json" title="JSON Feed 1.0"/>
|
||||
%VITE_CUSTOM_HEAD%
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "md-blog",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"repository": "https://github.com/klemek/md-blog",
|
||||
@@ -50,4 +50,4 @@
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-23
@@ -1,10 +1,7 @@
|
||||
import fs from 'fs'
|
||||
import process from 'process'
|
||||
import { Feed } from 'feed'
|
||||
|
||||
try {
|
||||
process.loadEnvFile()
|
||||
} catch {}
|
||||
import articlesConfig from './articles/config.json'
|
||||
|
||||
function getFiles(dir: string): string[] {
|
||||
return fs.readdirSync(dir).flatMap((name) => {
|
||||
@@ -31,10 +28,6 @@ function readArticleMetadata(path: string): Record<string, string> | null {
|
||||
const metadata: Record<string, string> = {
|
||||
path: path.replaceAll('/index.md', ''),
|
||||
}
|
||||
const dateMatch = path.match(/(\d{4}\/\d{2}\/\d{2})/)
|
||||
if (dateMatch && dateMatch[1]) {
|
||||
metadata['date'] = dateMatch[1].replaceAll('/', '-')
|
||||
}
|
||||
do {
|
||||
subMatch = METADATA_REGEX.exec(match[1])
|
||||
if (subMatch && subMatch[1] && subMatch[2]) {
|
||||
@@ -49,9 +42,9 @@ function formatArticlePage(metadata: Record<string, string>, baseHtml: string):
|
||||
outHtml = outHtml.replace(/<.*?property="og:url".*?>/gm, '')
|
||||
outHtml = outHtml.replace(
|
||||
/<\/head>/gm,
|
||||
`<meta property="og:url" content="${process.env.VITE_BASE_URL}${metadata.path}/">\n</head>`,
|
||||
`<meta property="og:url" content="${articlesConfig['base_url']}${metadata.path}/">\n</head>`,
|
||||
)
|
||||
const blog_title = process.env.VITE_APP_TITLE?.replace(/(<([^>]+)>)/gi, '').trim()
|
||||
const blog_title = articlesConfig['title']?.replace(/(<([^>]+)>)/gi, '').trim()
|
||||
if (metadata.title) {
|
||||
const title = metadata.title.replace(/(<([^>]+)>)/gi, '').trim()
|
||||
outHtml = outHtml.replace(/<title>.*?<\/title>/gm, `<title>${blog_title} — ${title}</title>`)
|
||||
@@ -70,7 +63,7 @@ function formatArticlePage(metadata: Record<string, string>, baseHtml: string):
|
||||
outHtml = outHtml.replace(/<.*?property="og:image".*?>/gm, '')
|
||||
outHtml = outHtml.replace(
|
||||
/<\/head>/gm,
|
||||
`<meta property="og:image" content="${metadata.thumbnail.replace('./', process.env.VITE_BASE_URL + metadata.path + '/')}">\n</head>`,
|
||||
`<meta property="og:image" content="${metadata.thumbnail.replace('./', articlesConfig['base_url'] + metadata.path + '/')}">\n</head>`,
|
||||
)
|
||||
}
|
||||
return outHtml
|
||||
@@ -81,9 +74,9 @@ function addFeedArticle(metadata: Record<string, string>, feed: Feed) {
|
||||
feed.addItem({
|
||||
title: metadata.title.replace(/(<([^>]+)>)/gi, '').trim(),
|
||||
id: metadata.path,
|
||||
link: `${process.env.VITE_BASE_URL}${metadata.path}/`,
|
||||
link: `${articlesConfig['base_url']}${metadata.path}/`,
|
||||
date: new Date(Date.parse(metadata.date)),
|
||||
image: metadata.thumbnail.replace('./', process.env.VITE_BASE_URL + metadata.path + '/'),
|
||||
image: metadata.thumbnail.replace('./', articlesConfig['base_url'] + metadata.path + '/'),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -96,21 +89,21 @@ if (!indexContent) {
|
||||
}
|
||||
|
||||
const metadatas = getFiles('articles')
|
||||
.filter((path) => path.match(/\d{4}\/\d{2}\/\d{2}\/index.md$/))
|
||||
.filter((path) => path.match(/\/index.md$/))
|
||||
.map((path) => readArticleMetadata(path))
|
||||
.filter((metadata) => !!metadata)
|
||||
|
||||
const feed = new Feed({
|
||||
title: process.env.VITE_APP_TITLE?.replace(/(<([^>]+)>)/gi, '').trim() ?? '',
|
||||
id: process.env.VITE_BASE_URL,
|
||||
link: process.env.VITE_BASE_URL,
|
||||
language: process.env.VITE_APP_LANG,
|
||||
favicon: process.env.VITE_BASE_URL + '/articles/favicon.ico',
|
||||
title: articlesConfig['title']?.replace(/(<([^>]+)>)/gi, '').trim() ?? '',
|
||||
id: articlesConfig['base_url'],
|
||||
link: articlesConfig['base_url'],
|
||||
language: articlesConfig['lang'],
|
||||
favicon: articlesConfig['base_url'] + 'articles/favicon.ico',
|
||||
generator: 'md-blog',
|
||||
feedLinks: {
|
||||
json: process.env.VITE_BASE_URL + 'feed.json',
|
||||
atom: process.env.VITE_BASE_URL + 'atom.xml',
|
||||
rss: process.env.VITE_BASE_URL + 'rss',
|
||||
json: articlesConfig['base_url'] + 'feed.json',
|
||||
atom: articlesConfig['base_url'] + 'atom.xml',
|
||||
rss: articlesConfig['base_url'] + 'rss',
|
||||
},
|
||||
updated: new Date(
|
||||
Math.max(
|
||||
@@ -129,5 +122,8 @@ metadatas.forEach((metadata) => {
|
||||
})
|
||||
|
||||
fs.writeFileSync('dist/feed.json', feed.json1())
|
||||
console.info(`Wrote dist/feed.json`)
|
||||
fs.writeFileSync('dist/atom.xml', feed.atom1())
|
||||
fs.writeFileSync('dist/rss', feed.rss2())
|
||||
console.info(`Wrote dist/atom.xml`)
|
||||
fs.writeFileSync('dist/rss.xml', feed.rss2())
|
||||
console.info(`Wrote dist/rss.xml`)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { REPOSITORY, NAME, VERSION, BASE_URL } from '@/lib/meta'
|
||||
import { REPOSITORY, NAME, VERSION, BASE_URL, TITLE, COPYRIGHT } from '@/lib/meta'
|
||||
import { stripHTML } from '@/lib/strings';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -8,10 +9,8 @@ import { REPOSITORY, NAME, VERSION, BASE_URL } from '@/lib/meta'
|
||||
</template>
|
||||
<hr />
|
||||
<footer>
|
||||
<small>
|
||||
{{ new Date().getFullYear() }} — Made with
|
||||
<a :href="REPOSITORY">{{ NAME }} {{ VERSION }}</a> —
|
||||
<a :href="BASE_URL + 'atom.xml'"><i icon="rss"></i> RSS</a>
|
||||
</small>
|
||||
{{ stripHTML(TITLE) }} © {{ new Date().getFullYear() }}, <span v-html="COPYRIGHT"></span> | Made with
|
||||
<a :href="REPOSITORY">{{ NAME }} {{ VERSION }}</a> |
|
||||
<a :href="BASE_URL + 'atom.xml'"><i icon="rss"></i> RSS</a>
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
+23
-11
@@ -1,16 +1,14 @@
|
||||
import type { MarkdownData, Article, ArticleMetadata } from '@interfaces'
|
||||
import { dateFromParts } from './dates'
|
||||
import katex from 'katex'
|
||||
|
||||
function parseMetadata(
|
||||
srcAttributes: Record<string, unknown>,
|
||||
pathPrefix: string,
|
||||
date: Date,
|
||||
): ArticleMetadata {
|
||||
return {
|
||||
path: pathPrefix,
|
||||
title: decodeURIComponent((srcAttributes.title as string) ?? 'Untitled'),
|
||||
date: date,
|
||||
date: new Date(Date.parse((srcAttributes.date as string) ?? '')),
|
||||
author: decodeURIComponent((srcAttributes.author as string) ?? ''),
|
||||
thumbnail: (srcAttributes.thumbnail as string) ?? '',
|
||||
draft: !!srcAttributes.draft,
|
||||
@@ -55,7 +53,10 @@ function transformHtml(srcHtml: string): string {
|
||||
return outHtml
|
||||
}
|
||||
|
||||
export async function loadArticle(date: Date): Promise<Article | null> {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export async function loadArticleOld(date: Date): Promise<Article | null> {
|
||||
const year = date.getFullYear().toString()
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0')
|
||||
const day = date.getDate().toString().padStart(2, '0')
|
||||
@@ -63,7 +64,23 @@ export async function loadArticle(date: Date): Promise<Article | null> {
|
||||
try {
|
||||
const data = (await import(`@articles/${year}/${month}/${day}/index.md`)) as MarkdownData
|
||||
return {
|
||||
metadata: parseMetadata(data.attributes, path, date),
|
||||
metadata: parseMetadata(data.attributes, path),
|
||||
html: transformHtml(data.html),
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadArticle(path: string): Promise<Article | null> {
|
||||
const raw_articles = import.meta.glob('@articles/**/index.md')
|
||||
const key = `/articles/${path}index.md`
|
||||
if (!raw_articles[key]) return null
|
||||
try {
|
||||
const data = (await raw_articles[key]()) as MarkdownData
|
||||
return {
|
||||
metadata: parseMetadata(data.attributes, path),
|
||||
html: transformHtml(data.html),
|
||||
}
|
||||
} catch (ex) {
|
||||
@@ -79,12 +96,7 @@ export async function listArticles(): Promise<ArticleMetadata[]> {
|
||||
Object.keys(raw_articles).map(async (key) => {
|
||||
if (!raw_articles[key]) return null
|
||||
const data = (await raw_articles[key]()) as MarkdownData
|
||||
const match = key.match(/\/(\d+)\/(\d+)\/(\d+)\//)
|
||||
if (match === null) {
|
||||
return null
|
||||
}
|
||||
const date = dateFromParts(match[1], match[2], match[3])
|
||||
return parseMetadata(data.attributes, key.replace('index.md', ''), date)
|
||||
return parseMetadata(data.attributes, key.replace('index.md', ''))
|
||||
}),
|
||||
)
|
||||
).filter((item) => item !== null)
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
export function dateFromParts(
|
||||
year: string | undefined,
|
||||
month: string | undefined,
|
||||
day: string | undefined,
|
||||
): Date {
|
||||
return new Date(parseInt(year ?? ''), parseInt(month ?? '') - 1, parseInt(day ?? ''))
|
||||
}
|
||||
|
||||
export function simpleDateFormat(date: Date): string {
|
||||
return (
|
||||
date.getFullYear() +
|
||||
|
||||
@@ -5,4 +5,5 @@ export const VERSION = packageJson.version
|
||||
export const REPOSITORY = packageJson.repository
|
||||
export const TITLE = import.meta.env.VITE_APP_TITLE
|
||||
export const SIGNATURE = import.meta.env.VITE_APP_SIGNATURE
|
||||
export const COPYRIGHT = import.meta.env.VITE_APP_COPYRIGHT
|
||||
export const BASE_URL = import.meta.env.BASE_URL
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{ path: '/', component: HomeView },
|
||||
{ path: '/articles/:year(\\d{4})/:month(\\d{2})/:day(\\d{2})/', component: ArticleView },
|
||||
{ path: '/articles/:pathMatch(.*)/', component: ArticleView },
|
||||
{ path: '/:pathMatch(.*)', component: NotFoundView },
|
||||
],
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ref, onBeforeMount } from 'vue'
|
||||
import { loadArticle } from '@lib/articles'
|
||||
import { useRoute, onBeforeRouteUpdate, type RouteLocation } from 'vue-router'
|
||||
import NotFoundView from './NotFoundView.vue'
|
||||
import { dateFromParts, simpleDateFormat } from '@lib/dates'
|
||||
import { simpleDateFormat } from '@lib/dates'
|
||||
import { SIGNATURE, TITLE } from '@lib/meta'
|
||||
import PageFooter from '@components/PageFooter.vue'
|
||||
import { stripHTML } from '@/lib/strings'
|
||||
@@ -15,13 +15,7 @@ const route = useRoute()
|
||||
|
||||
async function loadPage(target: RouteLocation) {
|
||||
loading.value = true
|
||||
article.value = await loadArticle(
|
||||
dateFromParts(
|
||||
target.params.year as string,
|
||||
target.params.month as string,
|
||||
target.params.day as string,
|
||||
),
|
||||
)
|
||||
article.value = await loadArticle(target.params.pathMatch as string)
|
||||
window.document.title =
|
||||
stripHTML(TITLE) + ' — ' + stripHTML(article.value?.metadata.title ?? 'Not Found')
|
||||
loading.value = false
|
||||
|
||||
+9
-4
@@ -4,14 +4,19 @@ import vue from '@vitejs/plugin-vue'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
import { plugin as mdPlugin, Mode } from 'vite-plugin-markdown'
|
||||
|
||||
import articlesConfig from './articles/config.json'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default ({ mode }: { mode: string }) => {
|
||||
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
|
||||
|
||||
process.env.VITE_APP_TITLE_NO_HTML = process.env.VITE_APP_TITLE?.replace(
|
||||
/(<([^>]+)>)/gi,
|
||||
'',
|
||||
).trim()
|
||||
process.env.VITE_BASE_URL = articlesConfig['base_url']
|
||||
process.env.VITE_APP_TITLE = articlesConfig['title']
|
||||
process.env.VITE_APP_TITLE_NO_HTML = articlesConfig['title'].replace(/(<([^>]+)>)/gi, '').trim()
|
||||
process.env.VITE_APP_LANG = articlesConfig['lang']
|
||||
process.env.VITE_APP_SIGNATURE = articlesConfig['signature']
|
||||
process.env.VITE_CUSTOM_HEAD = articlesConfig['custom_head']
|
||||
process.env.VITE_APP_COPYRIGHT = articlesConfig['copyright']
|
||||
|
||||
return defineConfig({
|
||||
plugins: [vue(), vueDevTools(), mdPlugin({ mode: [Mode.HTML] })],
|
||||
|
||||
Reference in New Issue
Block a user