feat: enhance SEO settings and improve title extraction

- Prioritize SEO settings from page data over environment variables
- Improve title extraction logic to handle new line characters
- Set SEO parameters for specific pages to improve search visibility
This commit is contained in:
ccbikai
2024-11-14 20:37:13 +08:00
parent 15e27d475f
commit b4a5dd021c
7 changed files with 26 additions and 5 deletions

View File

@@ -22,8 +22,8 @@ const seoParams = {
title: seo?.title,
description: seo?.text ?? channel?.description,
canonical,
noindex: getEnv(import.meta.env, Astro, 'NOINDEX'),
nofollow: getEnv(import.meta.env, Astro, 'NOFOLLOW'),
noindex: seo?.noindex ?? getEnv(import.meta.env, Astro, 'NOINDEX'),
nofollow: seo?.nofollow ?? getEnv(import.meta.env, Astro, 'NOFOLLOW'),
openGraph: {
basic: {
type: 'website',
@@ -33,7 +33,7 @@ const seoParams = {
},
optional: {
description: seo?.text ?? channel?.description,
locale: getEnv(import.meta.env, Astro, 'LOCALE'),
locale,
},
},
extend: {

View File

@@ -131,7 +131,7 @@ function getPost($, item, { channel, staticProxy, index = 0 }) {
const content = $(item).find('.js-message_reply_text')?.length > 0
? modifyHTMLContent($, $(item).find('.tgme_widget_message_text.js-message_text'), { index })
: modifyHTMLContent($, $(item).find('.tgme_widget_message_text'), { index })
const title = content?.text()?.match(/^.*?(?=[。:]|http\S)/g)?.[0] ?? content?.text() ?? ''
const title = content?.text()?.match(/^.*?(?=[。\n]|http\S)/g)?.[0] ?? content?.text() ?? ''
const id = $(item).attr('data-post')?.replace(new RegExp(`${channel}/`, 'i'), '')
const tags = $(content).find('a[href^="?q="]')?.each((_index, a) => {

View File

@@ -5,6 +5,10 @@ import { getChannelInfo } from '../../lib/telegram'
const channel = await getChannelInfo(Astro, {
after: Astro.params.cursor,
})
channel.seo = {
noindex: true,
}
---
<List channel={channel} />

View File

@@ -5,6 +5,10 @@ import { getChannelInfo } from '../../lib/telegram'
const channel = await getChannelInfo(Astro, {
before: Astro.params.cursor,
})
channel.seo = {
noindex: true,
}
---
<List channel={channel} />

View File

@@ -6,6 +6,10 @@ import { getEnv } from '../lib/env'
const channel = await getChannelInfo(Astro)
channel.seo = {
title: 'Links',
}
const links = (getEnv(import.meta.env, Astro, 'LINKS') || '')
.split(';')
.filter(Boolean)

View File

@@ -2,9 +2,14 @@
import List from '../../components/list.astro'
import { getChannelInfo } from '../../lib/telegram'
const q = Astro.url.searchParams.get('q') || Astro.params.q
const channel = await getChannelInfo(Astro, {
q: Astro.url.searchParams.get('q') || Astro.params.q,
q,
})
channel.seo = {
title: `${q}`,
}
---
<List channel={channel} before={false} after={false} />

View File

@@ -6,6 +6,10 @@ import { getEnv } from '../lib/env'
const channel = await getChannelInfo(Astro)
channel.seo = {
title: 'Tags',
}
const tags = (getEnv(import.meta.env, Astro, 'TAGS') || '').split(',')
---