From 98a1030907f0c2272f5c36dea6ac8a18961c0e30 Mon Sep 17 00:00:00 2001 From: ccbikai Date: Wed, 6 Nov 2024 20:01:40 +0800 Subject: [PATCH] feat: add support for links and navigation in sidebar --- .env.example | 4 +++- README.md | 6 ++++++ README.zh-cn.md | 6 ++++++ src/layouts/base.astro | 33 +++++++++++++++++++++++++++++++ src/pages/links.astro | 44 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/pages/links.astro diff --git a/.env.example b/.env.example index 4655d8d..59205c9 100644 --- a/.env.example +++ b/.env.example @@ -21,4 +21,6 @@ TELEGRAM_HOST=telegram.dog STATIC_PROXY="" GOOGLE_SEARCH_SITE="" TAGS="" -COMMENTS="" \ No newline at end of file +COMMENTS="" +LINKS="" +NAVS="" \ No newline at end of file diff --git a/README.md b/README.md index 23faf50..1c2df99 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,12 @@ TAGS=tag1,tag2,tag3 ## Show comments COMMENTS=true + +## List of links in the Links page, Separate using commas and semicolons +LINKS=Title1,URL1;Title2,URL3;Title3,URL3; + +## Sidebar Navigation Item, Separate using commas and semicolons +NAVS=Title1,URL1;Title2,URL3;Title3,URL3; ``` ## 🙋🏻 FAQs diff --git a/README.zh-cn.md b/README.zh-cn.md index ecef902..e77ff14 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -124,6 +124,12 @@ TAGS=标签A,标签B,标签C ## 展示评论 COMMENTS=true + +## 链接页面中的超链接, 使用英文逗号和分号分割 +LINKS=Title1,URL1;Title2,URL3;Title3,URL3; + +## 侧边栏导航项, 使用英文逗号和分号分割 +NAVS=Title1,URL1;Title2,URL3;Title3,URL3; ``` ## 🙋🏻 常问问题 diff --git a/src/layouts/base.astro b/src/layouts/base.astro index cdb1804..e48f472 100644 --- a/src/layouts/base.astro +++ b/src/layouts/base.astro @@ -48,6 +48,17 @@ const searchAction = GOOGLE_SEARCH_SITE ? 'https://www.google.com/search' : '/se const HEADER_INJECT = getEnv(import.meta.env, Astro, 'HEADER_INJECT') const FOOTER_INJECT = getEnv(import.meta.env, Astro, 'FOOTER_INJECT') const TAGS = getEnv(import.meta.env, Astro, 'TAGS') +const LINKS = getEnv(import.meta.env, Astro, 'LINKS') +const navs = (getEnv(import.meta.env, Astro, 'NAVS') || '') + .split(';') + .filter(Boolean) + .map((link) => { + link = link.split(',') + return { + title: link[0], + href: link[1], + } + }) --- @@ -101,6 +112,28 @@ const TAGS = getEnv(import.meta.env, Astro, 'TAGS') ) : null } + { + LINKS ? ( + + ) : null + } + { + navs.map((nav) => ( + + )) + }
diff --git a/src/pages/links.astro b/src/pages/links.astro new file mode 100644 index 0000000..e2a8439 --- /dev/null +++ b/src/pages/links.astro @@ -0,0 +1,44 @@ +--- +import Layout from '../layouts/base.astro' +import Header from '../components/header.astro' +import { getChannelInfo } from '../lib/telegram' +import { getEnv } from '../lib/env' + +export const prerender = false +const channel = await getChannelInfo(Astro) + +const links = (getEnv(import.meta.env, Astro, 'LINKS') || '') + .split(';') + .filter(Boolean) + .map((link) => { + link = link.split(',') + return { + title: link[0], + href: link[1], + } + }) + +if (!links.length) { + return Astro.redirect('/') +} +--- + + + +
+ + +
Links
+ +
+ { + links.map((link) => ( + + )) + } +
+