✨ (title) use title notes for HTML title
This commit is contained in:
23
src/hooks/useTitleNotes.hook.ts
Normal file
23
src/hooks/useTitleNotes.hook.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||
import { useNotes } from '@/modules/note/hooks/useNotes'
|
||||
import { pathToNoteTitle } from '@/utils/noteTitle'
|
||||
import { useTitle } from '@vueuse/core'
|
||||
import { computed, watch } from 'vue'
|
||||
|
||||
export const generateTitle = (titles: string[]) => titles.join(' | ')
|
||||
|
||||
export const useTitleNotes = (prefix: string) => {
|
||||
const { stackedNotes } = useQueryStackedNotes()
|
||||
const { notes } = useNotes()
|
||||
const titleNotes = computed(() =>
|
||||
notes.value
|
||||
.filter((note) => stackedNotes.value.includes(note.sha ?? ''))
|
||||
.map((note) => pathToNoteTitle(note.path ?? ''))
|
||||
)
|
||||
|
||||
const title = useTitle(generateTitle([prefix, ...titleNotes.value]))
|
||||
|
||||
watch(titleNotes, () => {
|
||||
title.value = generateTitle([prefix, ...titleNotes.value])
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user