3 Commits

Author SHA1 Message Date
klemek 169f35b556 feat: copyright 2026-04-26 15:39:15 +02:00
klemek 8d7388835b fix: push on default branch only 2026-04-26 15:16:33 +02:00
klemek 34c410b687 feat: do not use path as date 2026-04-26 15:10:30 +02:00
11 changed files with 41 additions and 41 deletions
+2 -1
View File
@@ -3,7 +3,8 @@ on:
schedule:
- cron: "*/30 * * * *"
push:
branches:
- "main"
jobs:
build:
name: Build
+4
View File
@@ -19,7 +19,11 @@ bun run build
- [x] SPA and opengraph
- [x] build with github actions
- [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
View File
@@ -1,6 +1,6 @@
{
"name": "md-blog",
"version": "1.1.0",
"version": "1.3.0",
"private": true,
"type": "module",
"repository": "https://github.com/klemek/md-blog",
+1 -5
View File
@@ -28,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]) {
@@ -93,7 +89,7 @@ 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)
+5 -6
View File
@@ -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) }} &copy; {{ 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
View File
@@ -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)
-8
View File
@@ -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() +
+1
View File
@@ -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
View File
@@ -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 },
],
})
+2 -8
View File
@@ -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
+1
View File
@@ -16,6 +16,7 @@ export default ({ mode }: { mode: string }) => {
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] })],