Skip to content

Commit

Permalink
fix: improve root lang detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Apr 1, 2022
1 parent a32409b commit ff65e00
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
24 changes: 12 additions & 12 deletions demo/theme/src/.vuepress/config.ts
Expand Up @@ -18,18 +18,18 @@ export default defineHopeConfig({
],
],

locales: {
"/": {
lang: "en-US",
title: "Theme Demo",
description: "A demo for vuepress-theme-hope",
},
"/zh/": {
lang: "zh-CN",
title: "主题演示",
description: "vuepress-theme-hope 的演示",
},
},
// locales: {
// "/": {
// lang: "en-US",
// title: "Theme Demo",
// description: "A demo for vuepress-theme-hope",
// },
// "/zh/": {
// lang: "zh-CN",
// title: "主题演示",
// description: "vuepress-theme-hope 的演示",
// },
// },

themeConfig,
});
6 changes: 3 additions & 3 deletions packages/feed2/src/node/injectHead.ts
Expand Up @@ -29,7 +29,7 @@ export const injectLinkstoHead = (
type,
href: resolveUrl(options["/"].hostname, base, fileName),
title: `${
siteData.title || siteData.locales["/"].title || ""
siteData.title || siteData.locales["/"]?.title || ""
} ${name} Feed`,
},
];
Expand Down Expand Up @@ -78,9 +78,9 @@ export const injectLinkstoHead = (
type,
href: resolveUrl(localeOptions.hostname, base, fileName),
title: `${
siteData.locales[pathLocale].title ||
siteData.locales[pathLocale]?.title ||
siteData.title ||
siteData.locales["/"].title ||
siteData.locales["/"]?.title ||
""
} ${name} Feed`,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/seo2/src/node/seo.ts
Expand Up @@ -34,9 +34,9 @@ export const generateSeo = (
const { siteData } = app;

const title =
siteData.locales[page.pathLocale].title ||
siteData.locales[page.pathLocale]?.title ||
siteData.title ||
siteData.locales["/"].title ||
siteData.locales["/"]?.title ||
"";
const author =
pageAuthor === false ? [] : getAuthor(pageAuthor || options.author);
Expand Down
9 changes: 1 addition & 8 deletions packages/shared/src/node/locales/helpers.ts
Expand Up @@ -60,14 +60,7 @@ export const getRootLang = (app: App): string => {
if (siteLocales?.["/"] && siteLocales["/"]?.lang)
return siteLocales["/"].lang;

// infer from themeLocale
const options = app.options as AppOptions<BaseThemeConfig>;
const themeLocales = options.themeConfig.locales;

if (themeLocales?.["/"] && themeLocales["/"]?.lang)
return themeLocales["/"].lang;

return "en-US";
return app.siteData.lang;
};

/**
Expand Down

0 comments on commit ff65e00

Please sign in to comment.