Skip to content

Commit

Permalink
feat(theme): make language dropdown tree shakable
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 23, 2022
1 parent abe8a03 commit 06f09c4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import type {

import "../styles/navbar.scss";

declare const HAS_MULTIPLE_LANGUAGES: boolean;

export default defineComponent({
name: "NavBar",

Expand Down Expand Up @@ -56,7 +58,7 @@ export default defineComponent({
return (): VNode[] => {
const map: Record<NavbarComponent, VNode | null> = {
Brand: h(NavbarBrand),
Language: h(LanguageDropdown),
Language: HAS_MULTIPLE_LANGUAGES ? h(LanguageDropdown) : null,
Links: h(NavbarLinks),
Repo: h(RepoLink),
Outlook: h(OutlookButton),
Expand Down
9 changes: 8 additions & 1 deletion packages/theme/src/node/status.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import type { App } from "@vuepress/core";
import type { HopeThemeOptions } from "../shared/index.js";

export interface ThemeStatus {
enableBlog: boolean;
enableEncrypt: boolean;
enableSlide: boolean;
hasMultipleLanguages: boolean;
supportPageview: boolean;
}

export const getStatus = (themeOptions: HopeThemeOptions): ThemeStatus => {
export const getStatus = (
app: App,
themeOptions: HopeThemeOptions
): ThemeStatus => {
const { locales } = app.options;
const { plugins = {} } = themeOptions;

return {
Expand All @@ -17,6 +23,7 @@ export const getStatus = (themeOptions: HopeThemeOptions): ThemeStatus => {
("admin" in themeOptions.encrypt || "config" in themeOptions.encrypt)
),
enableSlide: Boolean(plugins.mdEnhance && plugins.mdEnhance.presentation),
hasMultipleLanguages: Object.keys(locales).length > 1,
supportPageview: Boolean(
plugins.comment && plugins.comment.provider === "Waline"
),
Expand Down
3 changes: 2 additions & 1 deletion packages/theme/src/node/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const hopeTheme =

if (legacy) checkStyle(app);

const status = getStatus(options);
const status = getStatus(app, options);
const themeConfig = getThemeConfig(app, themeOptions, status);
const icons = status.enableBlog ? checkSocialMediaIcons(themeConfig) : {};

Expand All @@ -63,6 +63,7 @@ export const hopeTheme =

define: () => ({
ENABLE_BLOG: status.enableBlog,
HAS_MULTIPLE_LANGUAGES: status.hasMultipleLanguages,
SUPPORT_PAGEVIEW: status.supportPageview,
}),

Expand Down

0 comments on commit 06f09c4

Please sign in to comment.