Merge branch 'miantiao-me:main' into main

This commit is contained in:
2026-05-26 09:50:46 +08:00
committed by GitHub
6 changed files with 38 additions and 12 deletions

View File

@@ -49,6 +49,7 @@ English | [简体中文](./README.zh-cn.md)
- [Appinn Talk](https://talk.appinn.net/) - [Appinn Talk](https://talk.appinn.net/)
- [小报童优惠与排行榜](https://youhui.xiaobaoto.com/) - [小报童优惠与排行榜](https://youhui.xiaobaoto.com/)
- [热干面拌 10 号土豆泥](https://memo.moran.im/) - [热干面拌 10 号土豆泥](https://memo.moran.im/)
- [万事屋工程部](https://t.wanshiwu.fyi/)
### Platform ### Platform

View File

@@ -48,7 +48,7 @@
- [Abner's memos](https://memos.abnerz6.top/) - [Abner's memos](https://memos.abnerz6.top/)
- [小众软件的发现](https://talk.appinn.net/) - [小众软件的发现](https://talk.appinn.net/)
- [小报童优惠与排行榜](https://youhui.xiaobaoto.com/) - [小报童优惠与排行榜](https://youhui.xiaobaoto.com/)
- [热干面拌 10 号土豆泥](https://memo.moran.im/) - [热干面拌 10 号土豆泥](https://memo.moran.im/)
### 平台 ### 平台

View File

@@ -39,6 +39,7 @@ const tagStandaloneClass = 'pt-[30px]'
const tagLinkClass = const tagLinkClass =
'inline-block rounded-[4px] border border-line px-[10px] py-[2px] text-muted no-underline hover:border-accent hover:text-accent hover:no-underline' 'inline-block rounded-[4px] border border-line px-[10px] py-[2px] text-muted no-underline hover:border-accent hover:text-accent hover:no-underline'
const commentsClass = 'ml-[3px] border-l-2 border-line pb-6 pl-[15px] pt-[6px] sm:pl-[30px]' const commentsClass = 'ml-[3px] border-l-2 border-line pb-6 pl-[15px] pt-[6px] sm:pl-[30px]'
const getTagHref = (tag: string) => `/search/result?q=${encodeURIComponent(`#${tag}`)}`
--- ---
<article class={articleClass} style={{ 'view-transition-name': `post-${post.id}` }}> <article class={articleClass} style={{ 'view-transition-name': `post-${post.id}` }}>
@@ -84,8 +85,8 @@ const commentsClass = 'ml-[3px] border-l-2 border-line pb-6 pl-[15px] pt-[6px] s
hasTags && ( hasTags && (
<footer class:list={[tagBoxClass, tagPaddingClass, !hasContent && tagStandaloneClass]}> <footer class:list={[tagBoxClass, tagPaddingClass, !hasContent && tagStandaloneClass]}>
<span class="tag-icon" aria-hidden="true" /> <span class="tag-icon" aria-hidden="true" />
{post.tags.map((tag) => ( {post.tags.map((tag: string) => (
<a href={`/search/%23${tag}`} title={tag} class={tagLinkClass}> <a href={getTagHref(tag)} title={tag} class={tagLinkClass}>
{tag} {tag}
</a> </a>
))} ))}

View File

@@ -515,7 +515,7 @@ async function extractPost($: CheerioAPI, item: AnyNode | null, options: Extract
const tagLink = $(tagNode) const tagLink = $(tagNode)
const tagText = tagLink.text() const tagText = tagLink.text()
tagLink.attr('href', `/search/${encodeURIComponent(tagText)}`) tagLink.attr('href', `/search/result?q=${encodeURIComponent(tagText)}`)
const normalizedTag = tagText.replace('#', '') const normalizedTag = tagText.replace('#', '')
if (normalizedTag) { if (normalizedTag) {

View File

@@ -1,17 +1,37 @@
import { defineMiddleware } from 'astro:middleware' import { defineMiddleware } from 'astro:middleware'
function getEncodedTagSearchQuery(pathname: string): string {
if (!pathname.startsWith('/search/%23')) {
return ''
}
try {
return decodeURIComponent(pathname.slice('/search/'.length))
}
catch {
return ''
}
}
export const onRequest = defineMiddleware(async (context, next) => { export const onRequest = defineMiddleware(async (context, next) => {
context.locals.SITE_URL = `${import.meta.env.SITE ?? ''}${import.meta.env.BASE_URL}` context.locals.SITE_URL = `${import.meta.env.SITE ?? ''}${import.meta.env.BASE_URL}`
context.locals.RSS_URL = `${context.locals.SITE_URL}rss.xml` context.locals.RSS_URL = `${context.locals.SITE_URL}rss.xml`
context.locals.RSS_PREFIX = '' context.locals.RSS_PREFIX = ''
if (context.url.pathname.startsWith('/search') && context.params.q?.startsWith('#')) { const querySearch = context.url.searchParams.get('q') || ''
const tag = context.params.q.replace('#', '') const legacyTagSearch = getEncodedTagSearchQuery(context.url.pathname)
context.locals.RSS_URL = `${context.locals.SITE_URL}rss.xml?tag=${tag}` const pathSearch = context.params.q || ''
const searchQuery = querySearch || legacyTagSearch || pathSearch
if (context.url.pathname.startsWith('/search') && searchQuery.startsWith('#')) {
const tag = searchQuery.replace('#', '')
context.locals.RSS_URL = `${context.locals.SITE_URL}rss.xml?tag=${encodeURIComponent(tag)}`
context.locals.RSS_PREFIX = `${tag} | ` context.locals.RSS_PREFIX = `${tag} | `
} }
const response = await next() const response = legacyTagSearch
? await context.rewrite(`/search/result?q=${encodeURIComponent(legacyTagSearch)}`)
: await next()
if (!response.bodyUsed) { if (!response.bodyUsed) {
if (response.headers.get('Content-type') === 'text/html') { if (response.headers.get('Content-type') === 'text/html') {

View File

@@ -11,10 +11,14 @@ channel.seo = {
title: 'Tags', title: 'Tags',
} }
const items = (getEnv(import.meta.env, Astro, 'TAGS') || '').split(',').map((tag) => ({ const items = (getEnv(import.meta.env, Astro, 'TAGS') || '')
href: `/search/%23${tag}`, .split(',')
label: tag, .map((tag) => tag.trim())
})) .filter(Boolean)
.map((tag) => ({
href: `/search/result?q=${encodeURIComponent(`#${tag}`)}`,
label: tag,
}))
--- ---
<Layout channel={channel}> <Layout channel={channel}>