nimiq-vitepress-theme
Version:
Nimiq UI theme for VitePress
33 lines (32 loc) • 1.36 kB
JavaScript
import { useChangelog as useChangelogNolebase } from "@nolebase/vitepress-plugin-git-changelog/client/composables/changelog";
import { createGlobalState, useTimeAgo } from "@vueuse/core";
import { useData } from "vitepress";
import { computed, onMounted } from "vue";
import { renderCommitMessage } from "../lib/html-renderer.mjs";
export const useChangelog = createGlobalState(() => {
const { frontmatter } = useData();
const { commits: _commits, useHmr } = useChangelogNolebase();
onMounted(useHmr);
const commits = computed(() => {
return _commits.value.sort((a, b) => b.date_timestamp - a.date_timestamp).map((commit) => ({
...commit,
formattedDate: useTimeAgo(commit.date_timestamp).value,
messageAsHTML: renderCommitMessage(commit.repo_url, commit.message),
date: new Date(commit.date_timestamp * 1e3),
href: commit.hash_url || `${commit.repo_url}/commit/${commit.hash}`,
shortHash: commit.hash.slice(0, 7)
}));
});
const repoURL = computed(() => commits.value.find((commit) => commit.repo_url)?.repo_url || "");
const showChangelog = computed(() => {
if (frontmatter.value.changelog !== void 0)
return !!frontmatter.value.changelog;
const layout = frontmatter.value.layout || "docs";
return layout === "docs";
});
return {
commits,
repoURL,
showChangelog
};
});