diff --git a/.env.example b/.env.example deleted file mode 100644 index d04815a..0000000 --- a/.env.example +++ /dev/null @@ -1,5 +0,0 @@ -VITE_BASE_URL=http://localhost:8080/ -VITE_APP_TITLE= My Blog -VITE_APP_SIGNATURE=By me -VITE_APP_LANG=en -VITE_CUSTOM_HEAD= \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 39e0ea7..e20cd3a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,12 +18,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 diff --git a/README.md b/README.md index 96fb25c..148fad2 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ ```bash git clone $REPOSITORY articles -cp .env.example .env -$EDITOR .env bun run build ``` @@ -20,6 +18,8 @@ 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 \ No newline at end of file +- [x] config in sub repo +- [ ] nav bar on top +- [ ] archive page +- [ ] link to previous/next article +- [ ] proper docs \ No newline at end of file diff --git a/index.html b/index.html index 0e77f25..3ae6756 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + %VITE_CUSTOM_HEAD% diff --git a/package.json b/package.json index 0b7481f..f0946fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "md-blog", - "version": "1.0.0", + "version": "1.1.0", "private": true, "type": "module", "repository": "https://github.com/klemek/md-blog", @@ -50,4 +50,4 @@ "engines": { "node": "^20.19.0 || >=22.12.0" } -} \ No newline at end of file +} diff --git a/post-build.ts b/post-build.ts index 4a505c1..95cfe8d 100644 --- a/post-build.ts +++ b/post-build.ts @@ -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) => { @@ -49,9 +46,9 @@ function formatArticlePage(metadata: Record, baseHtml: string): outHtml = outHtml.replace(/<.*?property="og:url".*?>/gm, '') outHtml = outHtml.replace( /<\/head>/gm, - `\n`, + `\n`, ) - 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>/gm, `<title>${blog_title} — ${title}`) @@ -70,7 +67,7 @@ function formatArticlePage(metadata: Record, baseHtml: string): outHtml = outHtml.replace(/<.*?property="og:image".*?>/gm, '') outHtml = outHtml.replace( /<\/head>/gm, - `\n`, + `\n`, ) } return outHtml @@ -81,9 +78,9 @@ function addFeedArticle(metadata: Record, 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 + '/'), }) } } @@ -101,16 +98,16 @@ const metadatas = getFiles('articles') .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 +126,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`) diff --git a/vite.config.ts b/vite.config.ts index b9e1fa0..e3fb92d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,14 +4,18 @@ 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'] return defineConfig({ plugins: [vue(), vueDevTools(), mdPlugin({ mode: [Mode.HTML] })],