🔍 Improve SEO and RSS feed!
This commit is contained in:
parent
8ae48257cf
commit
4464c6557a
@ -8,9 +8,15 @@ export default defineNuxtConfig({
|
|||||||
name: "Solsynth LLC",
|
name: "Solsynth LLC",
|
||||||
},
|
},
|
||||||
sitemap: {
|
sitemap: {
|
||||||
sources: [
|
cacheMaxAgeSeconds: 3600,
|
||||||
"/api/sitemap/posts",
|
sitemapsPathPrefix: "/sitemap",
|
||||||
],
|
sitemaps: {
|
||||||
|
posts: {
|
||||||
|
sources: [
|
||||||
|
"/api/sitemap/posts",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
i18n: {
|
i18n: {
|
||||||
@ -85,6 +91,7 @@ export default defineNuxtConfig({
|
|||||||
"@nuxtjs/sitemap",
|
"@nuxtjs/sitemap",
|
||||||
"@pinia/nuxt",
|
"@pinia/nuxt",
|
||||||
"@nuxtjs/i18n",
|
"@nuxtjs/i18n",
|
||||||
|
"nuxt-schema-org",
|
||||||
(_options, nuxt) => {
|
(_options, nuxt) => {
|
||||||
nuxt.hooks.hook("vite:extendConfig", (config) => {
|
nuxt.hooks.hook("vite:extendConfig", (config) => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -16,8 +16,16 @@
|
|||||||
"@nuxtjs/i18n": "^8.3.3",
|
"@nuxtjs/i18n": "^8.3.3",
|
||||||
"@nuxtjs/sitemap": "^6.0.0-beta.1",
|
"@nuxtjs/sitemap": "^6.0.0-beta.1",
|
||||||
"@pinia/nuxt": "^0.5.3",
|
"@pinia/nuxt": "^0.5.3",
|
||||||
|
"feed": "^4.2.2",
|
||||||
"nuxt": "^3.12.4",
|
"nuxt": "^3.12.4",
|
||||||
|
"nuxt-schema-org": "^3.3.9",
|
||||||
"pinia": "^2.2.1",
|
"pinia": "^2.2.1",
|
||||||
|
"rehype-sanitize": "^6.0.0",
|
||||||
|
"rehype-stringify": "^10.0.0",
|
||||||
|
"remark": "^15.0.1",
|
||||||
|
"remark-parse": "^11.0.0",
|
||||||
|
"remark-rehype": "^11.1.0",
|
||||||
|
"unified": "^11.0.5",
|
||||||
"vue": "latest"
|
"vue": "latest"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
4
public/robots.txt
Normal file
4
public/robots.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
User-agent: *
|
||||||
|
Allow: /
|
||||||
|
|
||||||
|
Sitemap: https://solsynth.dev/sitemap.xml
|
@ -6,6 +6,8 @@ export default defineSitemapEventHandler(async () => {
|
|||||||
|
|
||||||
return result.data.map((item: any) => asSitemapUrl({
|
return result.data.map((item: any) => asSitemapUrl({
|
||||||
loc: `/posts/${item.id}`,
|
loc: `/posts/${item.id}`,
|
||||||
|
lastmod: item.edited_at ?? item.published_at,
|
||||||
|
priority: 0.9,
|
||||||
_sitemap: "posts",
|
_sitemap: "posts",
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
|
79
server/routes/posts/feed.ts
Normal file
79
server/routes/posts/feed.ts
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import { Feed } from "feed"
|
||||||
|
import { unified } from "unified"
|
||||||
|
import rehypeSanitize from "rehype-sanitize"
|
||||||
|
import rehypeStringify from "rehype-stringify"
|
||||||
|
import remarkParse from "remark-parse"
|
||||||
|
import remarkRehype from "remark-rehype"
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
|
||||||
|
const feed = new Feed({
|
||||||
|
title: "Solar Network",
|
||||||
|
description: "Content all over solar network",
|
||||||
|
id: "https://solsynth.dev",
|
||||||
|
copyright: "All rights reserved © 2024 Solsynth LLC",
|
||||||
|
generator: "Solar Network Post Web Preview",
|
||||||
|
feedLinks: {
|
||||||
|
atom: "https://solsynth.dev/posts/feed",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const queries = getQuery<{
|
||||||
|
take?: number,
|
||||||
|
offset?: number,
|
||||||
|
type?: "atom" | "json" | "rss",
|
||||||
|
realmId?: number,
|
||||||
|
author?: string,
|
||||||
|
}>(event)
|
||||||
|
|
||||||
|
const searchQuery = new URLSearchParams({
|
||||||
|
"take": (queries.take ?? 50).toString(),
|
||||||
|
"offset": (queries.offset ?? 0).toString(),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (queries.realmId) {
|
||||||
|
searchQuery.set("realmId", queries.realmId.toString())
|
||||||
|
}
|
||||||
|
if (queries.author) {
|
||||||
|
searchQuery.set("author", queries.author)
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetch(`${config.public.solarNetworkApi}/cgi/interactive/posts?` + searchQuery)
|
||||||
|
const posts: any[] = (await res.json())["data"]
|
||||||
|
|
||||||
|
for (const post of posts) {
|
||||||
|
const content = await unified()
|
||||||
|
.use(remarkParse)
|
||||||
|
.use(remarkRehype)
|
||||||
|
.use(rehypeSanitize)
|
||||||
|
.use(rehypeStringify)
|
||||||
|
.process(post.body.content)
|
||||||
|
|
||||||
|
feed.addItem({
|
||||||
|
date: new Date(post.published_at),
|
||||||
|
link: `https://solsynth.dev/posts/${post.id}`,
|
||||||
|
title: post.body.title ?? `Post #${post.id}`,
|
||||||
|
description: post.body.description,
|
||||||
|
content: String(content),
|
||||||
|
author: [
|
||||||
|
{
|
||||||
|
name: post.author.nick,
|
||||||
|
link: `https://solsynth.dev/@${post.author.name}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
image: post.body.thumbnail ? `${config.public.solarNetworkApi}/cgi/files/attachments/${post.body.thumbnail}` : void 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setResponseHeader(event, "Content-Type", "application/rss+xml")
|
||||||
|
|
||||||
|
switch (queries.type) {
|
||||||
|
case "json":
|
||||||
|
return feed.json1()
|
||||||
|
case "rss":
|
||||||
|
return feed.rss2()
|
||||||
|
default:
|
||||||
|
return feed.atom1()
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user