Skip to content

Commit

Permalink
feat: enhance SEO settings and improve title extraction
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ccbikai committed Nov 14, 2024
1 parent 15e27d4 commit b4a5dd0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/layouts/base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -33,7 +33,7 @@ const seoParams = {
},
optional: {
description: seo?.text ?? channel?.description,
locale: getEnv(import.meta.env, Astro, 'LOCALE'),
locale,
},
},
extend: {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/telegram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions src/pages/after/[cursor].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
4 changes: 4 additions & 0 deletions src/pages/before/[cursor].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
4 changes: 4 additions & 0 deletions src/pages/links.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/pages/search/[q].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
4 changes: 4 additions & 0 deletions src/pages/tags.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')
---

Expand Down

0 comments on commit b4a5dd0

Please sign in to comment.