From ed0caf572776cf7d91fe81aeaf5f2269db2a8e48 Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 3 May 2025 12:08:21 +0800 Subject: [PATCH 1/7] feat: add mdx & sitemap support (for real) --- astro.config.mjs | 12 ++++++++++-- package.json | 1 + pnpm-lock.yaml | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index e842bf8..03b7219 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,16 +1,24 @@ import { defineConfig } from 'astro/config'; +import sitemap from '@astrojs/sitemap'; + +import mdx from '@astrojs/mdx'; + export default defineConfig({ site: 'https://terminal-blog.example.com', base: '/', trailingSlash: 'ignore', + build: { format: 'directory' }, + markdown: { shikiConfig: { theme: 'nord', wrap: true } - } -}); + }, + + integrations: [sitemap(), mdx()] +}); \ No newline at end of file diff --git a/package.json b/package.json index e378227..054bef6 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "dependencies": { "@astrojs/mdx": "^4.2.6", "@astrojs/rss": "^4.0.1", + "@astrojs/sitemap": "^3.3.1", "astro": "^5.2.5", "fuse.js": "^7.0.0", "ultrahtml": "^1.6.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c64b99a..bde962a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@astrojs/rss': specifier: ^4.0.1 version: 4.0.11 + '@astrojs/sitemap': + specifier: ^3.3.1 + version: 3.3.1 astro: specifier: ^5.2.5 version: 5.7.10(@types/node@22.15.3)(rollup@4.40.1)(typescript@5.8.3) @@ -52,6 +55,9 @@ packages: '@astrojs/rss@4.0.11': resolution: {integrity: sha512-3e3H8i6kc97KGnn9iaZBJpIkdoQi8MmR5zH5R+dWsfCM44lLTszOqy1OBfGGxDt56mpQkYVtZJWoxMyWuUZBfw==} + '@astrojs/sitemap@3.3.1': + resolution: {integrity: sha512-GRnDUCTviBSNfXJ0Jmur+1/C+z3g36jy79VyYggfe1uNyEYSTcmAfTTCmbytrRvJRNyJJnSfB/77Gnm9PiXRRg==} + '@astrojs/telemetry@3.2.1': resolution: {integrity: sha512-SSVM820Jqc6wjsn7qYfV9qfeQvePtVc1nSofhyap7l0/iakUKywj3hfy3UJAOV4sGV4Q/u450RD4AaCaFvNPlg==} engines: {node: ^18.17.1 || ^20.3.0 || >=22.0.0} @@ -500,9 +506,15 @@ packages: '@types/nlcst@2.0.3': resolution: {integrity: sha512-vSYNSDe6Ix3q+6Z7ri9lyWqgGhJTmzRjZRqyq15N0Z/1/UnVsno9G/N40NBijoYx2seFDIl0+B2mgAb9mezUCA==} + '@types/node@17.0.45': + resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==} + '@types/node@22.15.3': resolution: {integrity: sha512-lX7HFZeHf4QG/J7tBZqrCAXwz9J5RD56Y6MpP0eJkka8p+K0RY/yBTW7CYFJ4VGCclxqOLKmiGP5juQc6MKgcw==} + '@types/sax@1.2.7': + resolution: {integrity: sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==} + '@types/unist@2.0.11': resolution: {integrity: sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==} @@ -541,6 +553,9 @@ packages: resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} engines: {node: '>= 8'} + arg@5.0.2: + resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==} + argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} @@ -1289,6 +1304,9 @@ packages: engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true + sax@1.4.1: + resolution: {integrity: sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==} + semver@7.7.1: resolution: {integrity: sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==} engines: {node: '>=10'} @@ -1307,6 +1325,11 @@ packages: sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + sitemap@8.0.0: + resolution: {integrity: sha512-+AbdxhM9kJsHtruUF39bwS/B0Fytw6Fr1o4ZAIAEqA6cke2xcoO2GleBw9Zw7nRzILVEgz7zBM5GiTJjie1G9A==} + engines: {node: '>=14.0.0', npm: '>=6.0.0'} + hasBin: true + smol-toml@1.3.4: resolution: {integrity: sha512-UOPtVuYkzYGee0Bd2Szz8d2G3RfMfJ2t3qVdZUAozZyAk+a0Sxa+QKix0YCwjL/A1RR0ar44nCxaoN9FxdJGwA==} engines: {node: '>= 18'} @@ -1322,6 +1345,9 @@ packages: space-separated-tokens@2.0.2: resolution: {integrity: sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==} + stream-replace-string@2.0.0: + resolution: {integrity: sha512-TlnjJ1C0QrmxRNrON00JvaFFlNh5TTG00APw23j74ET7gkQpTASi6/L2fuiav8pzK715HXtUeClpBTw2NPSn6w==} + string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} @@ -1678,6 +1704,12 @@ snapshots: fast-xml-parser: 4.5.3 kleur: 4.1.5 + '@astrojs/sitemap@3.3.1': + dependencies: + sitemap: 8.0.0 + stream-replace-string: 2.0.0 + zod: 3.24.3 + '@astrojs/telemetry@3.2.1': dependencies: ci-info: 4.2.0 @@ -2031,10 +2063,16 @@ snapshots: dependencies: '@types/unist': 3.0.3 + '@types/node@17.0.45': {} + '@types/node@22.15.3': dependencies: undici-types: 6.21.0 + '@types/sax@1.2.7': + dependencies: + '@types/node': 22.15.3 + '@types/unist@2.0.11': {} '@types/unist@3.0.3': {} @@ -2062,6 +2100,8 @@ snapshots: normalize-path: 3.0.0 picomatch: 2.3.1 + arg@5.0.2: {} + argparse@2.0.1: {} aria-query@5.3.2: {} @@ -3343,6 +3383,8 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.40.1 fsevents: 2.3.3 + sax@1.4.1: {} + semver@7.7.1: {} sharp@0.33.5: @@ -3390,6 +3432,13 @@ snapshots: sisteransi@1.0.5: {} + sitemap@8.0.0: + dependencies: + '@types/node': 17.0.45 + '@types/sax': 1.2.7 + arg: 5.0.2 + sax: 1.4.1 + smol-toml@1.3.4: {} source-map-js@1.2.1: {} @@ -3398,6 +3447,8 @@ snapshots: space-separated-tokens@2.0.2: {} + stream-replace-string@2.0.0: {} + string-width@4.2.3: dependencies: emoji-regex: 8.0.0 From afd5f125a7ea13b054bfd8dcfd0914d08258be47 Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 3 May 2025 12:08:51 +0800 Subject: [PATCH 2/7] feat: lazy load search index --- src/components/Search.astro | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Search.astro b/src/components/Search.astro index 509dd52..ff77d2b 100644 --- a/src/components/Search.astro +++ b/src/components/Search.astro @@ -59,12 +59,13 @@ resultsElement.innerHTML = html; } - // Initialize search when the component mounts - initializeSearch(); + // Add event listener for search input const searchInput = document.getElementById('search-input'); searchInput.addEventListener('input', (e) => { + // Initialize search + initializeSearch(); performSearch(e.target.value); }); From 7d3987f1240c36dd93f2c23e67937037970f2700 Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 3 May 2025 13:03:41 +0800 Subject: [PATCH 3/7] feat: change the placeholder when there is no posts --- src/pages/blog.astro | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/pages/blog.astro b/src/pages/blog.astro index 2069217..69a0a2b 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -25,16 +25,7 @@ posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDat {posts.length === 0 && ( <>

- 2025-06-08 - My Terminal Setup -

-

- 2025-06-05 - The Art of Minimalism -

-

- 2025-06-01 - First Post + No posts here yet

)} From d5f81c0f81cf401440a1c85ea72ddfd15e6338af Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 3 May 2025 18:03:47 +0800 Subject: [PATCH 4/7] revert: fuse.js load search index on site load --- src/components/Search.astro | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/Search.astro b/src/components/Search.astro index ff77d2b..509dd52 100644 --- a/src/components/Search.astro +++ b/src/components/Search.astro @@ -59,13 +59,12 @@ resultsElement.innerHTML = html; } - + // Initialize search when the component mounts + initializeSearch(); // Add event listener for search input const searchInput = document.getElementById('search-input'); searchInput.addEventListener('input', (e) => { - // Initialize search - initializeSearch(); performSearch(e.target.value); }); From 1da8ae56c4e393736fc8519131e245c7520e7a1e Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 3 May 2025 18:04:08 +0800 Subject: [PATCH 5/7] feat: better dark mode switch --- src/components/ThemeSwitcher.astro | 38 +++++++++++++++++++++++------- src/styles/global.css | 29 ++++++++++++++++++++++- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/components/ThemeSwitcher.astro b/src/components/ThemeSwitcher.astro index 6e6d349..8fa544a 100644 --- a/src/components/ThemeSwitcher.astro +++ b/src/components/ThemeSwitcher.astro @@ -5,18 +5,38 @@ \ No newline at end of file diff --git a/src/styles/global.css b/src/styles/global.css index eaf49e8..f9f07d1 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -11,7 +11,30 @@ --terminal-red: #ef4444; --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; } - +/* Light theme */ +@media (prefers-color-scheme: light) { + :root { + --bg-color: #f3f4f6; + --text-color: #374151; + --accent-color: #3b82f6; + --border-color: #d1d5db; + --header-color: #1f2937; + --terminal-green: #059669; + --terminal-yellow: #d97706; + --terminal-red: #dc2626; + } + :root:not([data-theme="light"]) { + --bg-color: #1f2937; + --text-color: #a5b4cf; + --accent-color: #64a0ff; + --border-color: #3b4351; + --header-color: #83a2ce; + --terminal-green: #4ade80; + --terminal-yellow: #fbbf24; + --terminal-red: #ef4444; + } +} +/* Light theme override (for switch) */ :root[data-theme="light"] { --bg-color: #f3f4f6; --text-color: #374151; @@ -116,6 +139,10 @@ main { opacity: 0.7; } +.footer img { + vertical-align: middle; +} + /* Post styles */ .post-title { color: var(--header-color); From c6db8689b4159a88d36adec84f0c24795ac362e2 Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 3 May 2025 20:51:35 +0800 Subject: [PATCH 6/7] feat: even better theme switcher --- src/components/ThemeSwitcher.astro | 143 ++++++++++++++++++++++------- src/styles/global.css | 73 +++++++++++---- 2 files changed, 166 insertions(+), 50 deletions(-) diff --git a/src/components/ThemeSwitcher.astro b/src/components/ThemeSwitcher.astro index 8fa544a..78a8c17 100644 --- a/src/components/ThemeSwitcher.astro +++ b/src/components/ThemeSwitcher.astro @@ -1,42 +1,119 @@ --- --- - +
+ + +
- \ No newline at end of file diff --git a/src/styles/global.css b/src/styles/global.css index f9f07d1..8128d4a 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -143,6 +143,51 @@ main { vertical-align: middle; } +.footer .floating { + position: fixed; + bottom: 20px; + right: 30px; + z-index: 10; + display: flex; + flex-direction: column; + border: none; + outline: none; + padding: 15px; +} + + +#toTopBtn { + display: none; + background: var(--border-color); + border: none; + color: var(--text-color); + padding: 0.5rem 1rem; + font-family: var(--font-mono); + cursor: pointer; +} + +#toTopBtn:hover { + background: var(--accent-color); + color: var(--bg-color); +} +/* Theme Switcher */ +.theme-switcher { + background: var(--border-color); + border: none; + color: var(--text-color); + padding: 0.5rem 1rem; + font-family: var(--font-mono); + cursor: pointer; + transition: background-color 0.3s ease, color 0.3s ease; +} + +.theme-switcher:hover { + background: var(--accent-color); + color: var(--bg-color); +} + + + /* Post styles */ .post-title { color: var(--header-color); @@ -173,24 +218,18 @@ main { opacity: 0.7; } -/* Theme Switcher */ -.theme-switcher { - position: fixed; - top: 1rem; - right: 1rem; - background: var(--border-color); - border: none; - color: var(--text-color); - padding: 0.5rem 1rem; - border-radius: 4px; - font-family: var(--font-mono); - cursor: pointer; - transition: background-color 0.3s ease, color 0.3s ease; +/* helper Class */ +.fade-in { + opacity: 1; + transition-property: opacity; + transition-duration: .7s; + transition-timing-function: cubic-bezier(.4,0,1,1); } - -.theme-switcher:hover { - background: var(--accent-color); - color: var(--bg-color); +.fade-out { + opacity: 0; + transition-property: opacity; + transition-duration: .7s; + transition-timing-function: cubic-bezier(.4,0,1,1); } /* Media Queries */ From 350f6f386517cf44435e9248b2f2e12517cae5c2 Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 3 May 2025 20:53:47 +0800 Subject: [PATCH 7/7] feat: add back to top button and group with theme switcher --- src/components/BackToTop.astro | 27 +++++++++++++++++++++++++++ src/layouts/Layout.astro | 6 +++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/components/BackToTop.astro diff --git a/src/components/BackToTop.astro b/src/components/BackToTop.astro new file mode 100644 index 0000000..80dc6c2 --- /dev/null +++ b/src/components/BackToTop.astro @@ -0,0 +1,27 @@ +--- + +--- + + \ No newline at end of file diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index c505b7a..8da33c4 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -2,6 +2,7 @@ import '../styles/global.css'; import Search from '../components/Search.astro'; import ThemeSwitcher from '../components/ThemeSwitcher.astro'; +import BackToTop from "../components/BackToTop.astro"; import { siteConfig } from "../config"; interface Props { @@ -26,7 +27,6 @@ const { title, path = formattedPath } = Astro.props; {title} -
@@ -47,6 +47,10 @@ const { title, path = formattedPath } = Astro.props;