From 9ff763ece45f29a524cf54808e73309ff2e6f51d Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 10 May 2024 18:46:31 +0800 Subject: [PATCH] =?UTF-8?q?sitemap,robots=E6=94=AF=E6=8C=81NOTION=5FCONFIG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/robots.txt.js | 10 +++++----- lib/rss.js | 15 +++++++-------- pages/index.js | 2 +- pages/sitemap.xml.js | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/robots.txt.js b/lib/robots.txt.js index 4405164f..4dbc61c2 100644 --- a/lib/robots.txt.js +++ b/lib/robots.txt.js @@ -1,18 +1,18 @@ - import fs from 'fs' -import BLOG from '@/blog.config' +import { siteConfig } from './config' -export async function generateRobotsTxt() { +export async function generateRobotsTxt(NOTION_CONFIG) { + const LINK = siteConfig('LINK', '', NOTION_CONFIG) const content = ` # * User-agent: * Allow: / # Host - Host: ${BLOG.LINK} + Host: ${LINK} # Sitemaps - Sitemap: ${BLOG.LINK}/sitemap.xml + Sitemap: ${LINK}/sitemap.xml ` try { diff --git a/lib/rss.js b/lib/rss.js index b60a6ceb..8b09bdce 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -1,4 +1,3 @@ -import BLOG from '@/blog.config' import NotionPage from '@/components/NotionPage' import { getPostBlocks } from '@/lib/db/getSiteData' import { Feed } from 'feed' @@ -27,22 +26,22 @@ const createFeedContent = async post => { } export async function generateRss(NOTION_CONFIG, posts) { - const link = siteConfig('LINK', BLOG.LINK, NOTION_CONFIG) - const author = siteConfig('AUTHOR', BLOG.AUTHOR, NOTION_CONFIG) - const lang = siteConfig('LANG', BLOG.LANG, NOTION_CONFIG) - const subPath = siteConfig('SUB_PATH', BLOG.SUB_PATH, NOTION_CONFIG) + const link = siteConfig('LINK', '', NOTION_CONFIG) + const author = siteConfig('AUTHOR', '', NOTION_CONFIG) + const lang = siteConfig('LANG', '', NOTION_CONFIG) + const subPath = siteConfig('SUB_PATH', '', NOTION_CONFIG) const year = new Date().getFullYear() const feed = new Feed({ - title: BLOG.TITLE, - description: BLOG.DESCRIPTION, + title: siteConfig('TITLE', '', NOTION_CONFIG), + description: siteConfig('DESCRIPTION', '', NOTION_CONFIG), link: `${link}/${subPath}`, language: lang, favicon: `${link}/favicon.png`, copyright: `All rights reserved ${year}, ${author}`, author: { name: author, - email: BLOG.CONTACT_EMAIL, + email: siteConfig('CONTACT_EMAIL', '', NOTION_CONFIG), link: link } }) diff --git a/pages/index.js b/pages/index.js index 1b805730..eb0a2bd4 100644 --- a/pages/index.js +++ b/pages/index.js @@ -56,7 +56,7 @@ export async function getStaticProps(req) { } // 生成robotTxt - generateRobotsTxt() + generateRobotsTxt(props?.NOTION_CONFIG) // 生成Feed订阅 if (JSON.parse(BLOG.ENABLE_RSS)) { generateRss(props?.NOTION_CONFIG, props?.latestPosts || []) diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js index 48be36de..eb7f7bd8 100644 --- a/pages/sitemap.xml.js +++ b/pages/sitemap.xml.js @@ -17,7 +17,7 @@ export const getServerSideProps = async ctx => { pageId: id, from: 'sitemap.xml' }) - const link = siteConfig('LINK', BLOG.LINK, siteData.NOTION_CONFIG) + const link = siteConfig('LINK', '', siteData.NOTION_CONFIG) const localeFields = generateLocalesSitemap(link, siteData.allPages, locale) fields = fields.concat(localeFields) }