Skip to content

Commit

Permalink
Add missing titles composable
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jan 31, 2023
1 parent 4662685 commit 51549b8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/title.composable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { computed } from "vue";
import { useRoute } from "vue-router";
import { useI18n } from "vue-i18n";
import { useTitle } from "@vueuse/core";
import useLocale from "./i18n/locale.composable";
import { useCorpusStore } from "./store/corpus.store";

/** Handle the custom title/createTitle route meta options. */
export default function usePageTitle() {
const route = useRoute();
const { t } = useI18n();
const { th } = useLocale();
const corpusStore = useCorpusStore();
const corpusName = computed(() =>
th(corpusStore.corpora[route.params.corpusId]?.config?.name)
);

const title = computed(() =>
route.meta.title
? t(route.meta.title)
: route.meta.createTitle?.(t, corpusName.value, route.params)
);

useTitle(title, { titleTemplate: "%s | Mink" });
}

0 comments on commit 51549b8

Please sign in to comment.