:magify: Improve SEO

This commit is contained in:
LittleSheep 2024-12-19 22:40:26 +08:00
parent 15e1b3971f
commit 1bc50aecc5
8 changed files with 58 additions and 19 deletions

View File

@ -7,9 +7,20 @@ import icon from 'astro-icon'
import mdx from '@astrojs/mdx'
import sitemap from '@astrojs/sitemap'
// https://astro.build/config
export default defineConfig({
integrations: [tailwind(), icon(), mdx()],
site: 'https://solsynth.dev',
integrations: [
tailwind(),
icon(),
mdx(),
sitemap({
xslURL: '/sitemap.xsl',
i18n: { defaultLocale: 'en', locales: { en: 'en-US', 'zh-cn': 'zh-CN' } },
}),
],
prefetch: true,
i18n: {
locales: ['en', 'zh-cn'],

BIN
bun.lockb

Binary file not shown.

View File

@ -10,11 +10,13 @@
},
"dependencies": {
"@astrojs/mdx": "^4.0.2",
"@astrojs/sitemap": "^3.2.1",
"@astrojs/tailwind": "^5.1.3",
"@iconify-json/material-symbols": "^1.2.10",
"@iconify-json/simple-icons": "^1.2.16",
"astro": "^5.0.5",
"astro-icon": "^1.1.4",
"astro-seo": "^0.8.4",
"marked": "^15.0.4",
"sanitize-html": "^2.13.1",
"tailwindcss": "^3.4.16"

4
public/robots.txt Normal file
View File

@ -0,0 +1,4 @@
User-agent: *
Allow: /
Sitemap: https://solsynth.dev/sitemap-index.xml

View File

@ -1,6 +1,4 @@
---
export const prerender = false
import { Image } from 'astro:assets'
import { version } from '../../package.json'
@ -10,9 +8,11 @@ import { getRelativeLocaleUrl } from 'astro:i18n'
interface Props {
title?: string
trailingTitle?: string
}
const { title } = Astro.props
let { title, trailingTitle } = Astro.props
if(trailingTitle == null) trailingTitle = 'Solsynth LLC'
const locale = Astro.currentLocale ?? 'en'
---
@ -23,7 +23,8 @@ const locale = Astro.currentLocale ?? 'en'
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/png" href="/favicon.png" />
<title>{title ? `${title} | Solsynth LLC` : 'Solsynth LLC'}</title>
<link rel="sitemap" href="/sitemap-index.xml" />
<title>{title ? `${title} | ${trailingTitle}` : trailingTitle}</title>
</head>
<body>
<div class="navbar backdrop-blur fixed top-0 left-0 right-0 z-10">
@ -41,16 +42,7 @@ const locale = Astro.currentLocale ?? 'en'
<div class="flex-1 flex justify-end">
<ul class="menu menu-horizontal px-1">
<li><a>Link</a></li>
<li>
<details>
<summary>Parent</summary>
<ul class="bg-base-100 rounded-t-none p-2">
<li><a>Link 1</a></li>
<li><a>Link 2</a></li>
</ul>
</details>
</li>
<li><a href="/posts">Explore</a></li>
</ul>
</div>
</div>

View File

@ -3,6 +3,7 @@ export const prerender = false
import sanitizeHtml from 'sanitize-html'
import { Icon } from 'astro-icon/components'
import {SEO} from 'astro-seo'
import { marked } from 'marked'
import Layout from '@/layouts/Layout.astro'
@ -28,7 +29,33 @@ const content = sanitizeHtml(rawContent)
const attachments = await fetchAttachmentMeta(data.body.attachments)
---
<Layout title={data.body?.title ? data.body.title : `Post #${data.id}`}>
<head>
<SEO
title={data.body?.title ? data.body.title : `Post #${data.id}`}
description={data.body?.content}
openGraph={{
basic: {
title: data.body?.title ? data.body.title : `Post #${data.id}`,
type: "article",
image: data.body?.thumbnail ? getAttachmentUrl(data.body.thumbnail) : getAttachmentUrl(attachments.find(a => a.mimetype.startsWith('image'))?.rid),
url: `https://solsynth.dev/posts/${data.id}`
},
article: {
publishedTime: new Date(data.created_at).toISOString(),
modifiedTime: new Date(data.updated_at).toISOString(),
authors: ["@"+data.publisher.name],
}
}}
twitter={{
title: data.body?.title ? data.body.title : `Post #${data.id}`,
description: data.body?.content,
creator: "@"+data.publisher.name,
image: data.body?.thumbnail ? getAttachmentUrl(data.body.thumbnail) : getAttachmentUrl(attachments.find(a => a.mimetype.startsWith('image'))?.rid),
}}
/>
</head>
<Layout title={data.body?.title ? data.body.title : `Post #${data.id}`} trailingTitle='Solar Network'>
<div role="alert" class="alert shadow-lg px-12 m-0 rounded-none mb-5">
<Icon
name="material-symbols:ungroup"

View File

@ -45,7 +45,7 @@ async function parseContent(data: string, useBreaks: boolean = false) {
}
---
<Layout title="Posts">
<Layout title="Posts" trailingTitle='Solar Network'>
<div role="alert" class="alert shadow-lg px-12 m-0 rounded-none mb-5">
<Icon
name="material-symbols:ungroup"

View File

@ -1,4 +1,5 @@
export function getAttachmentUrl(identifier: string): string {
export function getAttachmentUrl(identifier?: string): string {
if (!identifier) return ''
if (identifier.startsWith('http')) {
return identifier
}
@ -13,7 +14,9 @@ export async function fetchAttachmentMeta(
const baseUrl = import.meta.env.PUBLIC_SOLAR_NETWORK_URL
const resp = await fetch(
`${baseUrl}/cgi/uc/attachments?take=${identifiers.length}&id=${identifiers.join(',')}`
`${baseUrl}/cgi/uc/attachments?take=${
identifiers.length
}&id=${identifiers.join(',')}`
)
if (resp.status !== 200) {
throw new Error(`Failed to fetch attachment meta: ${await resp.text()}`)