提问人:SoftTimur 提问时间:11/16/2023 更新时间:11/17/2023 访问量:24
非英语版本的纪录片网站的特定标题和关键字
Specific title and keywords for non-english versions of a docusaurus website
问:
我有一个由docusaurus制作的网站。最初是英文的,然后我用 .因此,像这样的页面用中文显示内容很好。2.0.0-beta.18
i18
https://www.mywebsite.com/zh-CN/docs/a-page
我正在改善网站的SEO。我了解到我们可以更好地写作和改进 SEO。所以我写了,如下图所示。然后我确实看到这些元数据出现在 HTML 中。title
keywords
docusaurus.config.js
title: 'mywebsite, toSEO'
{name: 'keywords', content: 'word, toSEO'}
但是,当我打开中文版的网站时,我看到这些元数据也出现在 HTML 中。所以我的问题是是否可以为中文版设置特定/不同的标题和关键字。
有人知道吗?
PS:(部分)docusaurus.config.js:
const path = require('path');
module.exports = {
title: 'my website, toSEO',
tagline: 'The tagline of my site',
onBrokenLinks: 'ignore',
url: 'https://www.mywebsite.com',
baseUrl: '/', // if we use GitHub Pages, we need to set this to '/docusaurus/', and also change routing links in some pages
favicon: 'img/favicon.ico',
organizationName: 'softtimur', // Usually your GitHub org/user name.
projectName: 'docusaurus', // Usually your repo name.
trailingSlash: false,
plugins: [
path.resolve(__dirname, './plugins/monaco-loader'),
],
themeConfig: {
metadata: [
{name: 'keywords', content: 'word, toSEO'},
],
navbar: {
title: 'my website',
logo: {
alt: 'My Site Logo',
src: 'img/logo.svg',
},
items: [
{
label: 'Documentation', position: 'left',
items: [
{ label: 'Introduction', to: 'docs/introduction' },
{ label: 'Getting Started', to: 'docs/try-samples' }
]
},
{ to: 'demo', label: 'Live Demo', position: 'left' }, // to src/pages/demo.js
{
label: 'Persons', position: 'left',
items: [
{ label: 'Get my website', to: 'docs/consumer-buy' },
{ label: 'Follow Free Videos and Contents', to: 'docs/free-videos' },
{ label: 'Request a Help', to: 'docs/help-your-work' }
]
},
{
label: 'Businesses', position: 'left',
items: [
{ label: 'Get my website Together', to: 'docs/group-buy' },
{ label: 'Other Services', to: 'docs/web-development' }
]
},
{
label: 'Language and Programming', position: 'left',
items: [
{ label: 'Course in English', to: 'https://go.mywebsite.com/RJ2HPz' },
{ label: 'Course in Chinese', to: 'https://go.mywebsite.com/2KjQzL' },
]
}
,
{
to: '#',
position: 'right',
},
{
to: '/logout',
label: 'Sign Out',
position: 'right',
},
{
to: '/login',
label: 'Sign In',
position: 'right',
},
{
type: 'localeDropdown',
position: 'right',
},
],
},
footer: {
style: 'dark',
links: [
{
title: 'Documentation',
items: [
{
label: 'Try samples',
to: 'docs/try-samples',
},
{
label: 'Installation',
to: 'docs/installation',
}
],
},
{
title: 'Philosophy and Research',
items: [
{
label: 'Fundamentals',
to: 'docs/fundamentals'
},
],
},
{
title: 'Community',
items: [
{
label: 'LinkedIn',
href: 'https://www.linkedin.com/in/softtimur/'
}
],
},
{
title: 'Company',
items: [
{
label: 'About Us',
to: 'docs/about-us'
},
{
label: '❤ We are hiring!',
to: 'docs/hiring'
}
],
}
],
},
},
presets: [
[
'@docusaurus/preset-classic',
{
googleAnalytics: {
trackingID: 'UA-68622074-6',
},
docs: {
sidebarPath: require.resolve('./sidebars.js'),
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
sitemap: {
changefreq: 'weekly',
priority: 0.5,
},
},
],
],
scripts : [
'/js/patch.js'
],
i18n: {
defaultLocale: 'en',
locales: ['en', 'zh-CN'], // Add 'zh-CN' here
localeConfigs: {
en: {
label: 'English',
htmlLang: 'en-GB',
},
'zh-CN': { // Add this section for Simplified Chinese
label: '简体中文',
htmlLang: 'zh-Hans',
},
},
}
};
答:
0赞
Sebastien Lorber
11/17/2023
#1
此处提出了一种解决方法:
https://github.com/facebook/docusaurus/issues/4542#issuecomment-1434839071
function getSiteTitle() {
switch(process.env.DOCUSAURUS_CURRENT_LOCALE) {
case "fr": return "Mon site en Français";
default: return "My English website";
}
}
评论
0赞
SoftTimur
11/17/2023
目前,我们正在使用 Docusaurus 2.0.0-beta.18。您建议我升级到哪个版本才能使用此功能?
评论