Skip to content

Commit

Permalink
fix(theme): fix getDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jun 10, 2022
1 parent 5917c08 commit e22a76b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
9 changes: 3 additions & 6 deletions packages/theme/src/client/composables/pageInfo.ts
@@ -1,4 +1,4 @@
import { usePageData, usePageFrontmatter, usePageLang } from "@vuepress/client";
import { usePageData, usePageFrontmatter } from "@vuepress/client";
import { computed, inject, reactive } from "vue";
import {
getAuthor,
Expand All @@ -13,7 +13,6 @@ import type {
AuthorInfo,
BasePageFrontMatter,
DateInfo,
DateOptions,
} from "vuepress-shared";
import type { GitData } from "@vuepress/plugin-git";
import type { ComputedRef } from "vue";
Expand Down Expand Up @@ -73,17 +72,15 @@ export const usePageTag = (): ComputedRef<PageTag[]> => {
export const usePageDate = (): ComputedRef<DateInfo | null> => {
const frontmatter = usePageFrontmatter<BasePageFrontMatter>();
const page = usePageData<{ git?: GitData }>();
const pageLang = usePageLang();

return computed(() => {
const { date } = frontmatter.value;
const options: DateOptions = { lang: pageLang.value, type: "date" };

if (date) return getDate(date, options);
if (date) return getDate(date);

const { createdTime } = page.value.git || {};

if (createdTime) return getDate(new Date(createdTime), options);
if (createdTime) return getDate(new Date(createdTime));

return null;
});
Expand Down
10 changes: 3 additions & 7 deletions packages/theme/src/client/module/blog/composables/articleInfo.ts
@@ -1,4 +1,3 @@
import { usePageLang } from "@vuepress/client";
import { computed, reactive, Ref } from "vue";
import {
getAuthor,
Expand Down Expand Up @@ -62,15 +61,12 @@ export const useArticleTag = (info: Ref<ArticleInfo>): TagRef => {

export type DateRef = ComputedRef<DateInfo | null>;

export const useArticleDate = (info: Ref<ArticleInfo>): DateRef => {
const pageLang = usePageLang();

return computed(() => {
export const useArticleDate = (info: Ref<ArticleInfo>): DateRef =>
computed(() => {
const { date } = info.value;

return date ? getDate(date, { lang: pageLang.value, type: "date" }) : null;
return date ? getDate(date) : null;
});
};

export const useArticleInfo = (
info: Ref<ArticleInfo>
Expand Down
Expand Up @@ -44,8 +44,7 @@ export const setupTimelines = (): void => {

// filter before sort
timelines.value.items.forEach(({ info, path }) => {
const { year, month, day } =
getDate(info.date, { type: "date" })?.info || {};
const { year, month, day } = getDate(info.date)?.info || {};

if (year && month && day) {
if (!timelineItems[0] || timelineItems[0].year !== year)
Expand Down

0 comments on commit e22a76b

Please sign in to comment.