Skip to content

Commit

Permalink
feat: follow frontmatter.gitInclude
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamOfIce committed Apr 6, 2023
1 parent bfdedce commit 166ff71
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
pnpm-lock.yaml
4 changes: 2 additions & 2 deletions src/client/components/i18nTip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getContent = (
case "untranslated":
return locale.untranslated.content(
linkRenderer,
guideLinks[i18nData?.localePath ?? sourcePath] ?? guideLinks[sourcePath]
guideLinks[i18nData?.pathLocale ?? sourcePath] ?? guideLinks[sourcePath]
);
case "outdated":
if (
Expand All @@ -51,7 +51,7 @@ const getContent = (
const pageData = usePageData<PageData>();
const locale = computed(
() =>
locales[pageData.value.i18n?.localePath ?? sourcePath] ??
locales[pageData.value.i18n?.pathLocale ?? sourcePath] ??
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
locales[sourcePath]!
);
Expand Down
14 changes: 12 additions & 2 deletions src/node/lib/pageData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getUpdatedTime } from "@vuepress/plugin-git";
import { path } from "@vuepress/utils";
import type { I18nPluginFrontmatter, Page } from "../../shared/types";
import type { I18nPluginInternalOptions } from "../options";
import { isGitRepo } from "../utils";
Expand All @@ -11,9 +12,10 @@ const addPageData = async (
const i18nFrontmatter = (page.frontmatter as I18nPluginFrontmatter)["_i18n"];
if (i18nFrontmatter?.filePathRelative)
page.filePathRelative = i18nFrontmatter.filePathRelative;
if (i18nFrontmatter?.pathLocale) page.pathLocale = i18nFrontmatter.pathLocale;

page.data.i18n ||= {
localePath: i18nFrontmatter?.localePath ?? page.pathLocale,
pathLocale: page.pathLocale,
sourceLink: page.path.replace(page.pathLocale, options.sourcePath),
untranslated: i18nFrontmatter?.untranslated ?? false,
};
Expand All @@ -23,7 +25,15 @@ const addPageData = async (
if (isGitRepo(cwd) && page.filePathRelative) {
page.data.i18n.updatedTime =
page.data.git?.updatedTime ??
(await getUpdatedTime([page.filePathRelative], cwd));
(await getUpdatedTime(
[
page.filePathRelative,
...(page.frontmatter.gitInclude ?? []).map((item) =>
path.join(page.filePathRelative, "..", item)
),
],
cwd
));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/node/lib/untranslated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const fillUntranslatedPages = async (
frontmatter: {
...page.frontmatter,
_i18n: {
localePath: prefix,
pathLocale: prefix,
untranslated: true,
},
} as PageFrontmatter<I18nPluginFrontmatter>,
Expand Down
5 changes: 3 additions & 2 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ interface I18nPluginLocaleData {
interface I18nPluginFrontmatter {
_i18n?: {
filePathRelative?: string;
localePath?: string;
pathLocale?: string;
untranslated?: boolean;
};
gitInclude?: string[];
tag?: string[];
}

interface I18nData {
localePath?: string;
pathLocale?: string;
outdated?: boolean;
sourceLink?: string;
sourceUpdatedTime?: number;
Expand Down

0 comments on commit 166ff71

Please sign in to comment.