✨ (title) use title notes for HTML title
This commit is contained in:
@@ -34,6 +34,7 @@ import { useImages } from '@/hooks/useImages.hook'
|
|||||||
import LinkedNotes from '@/components/LinkedNotes.vue'
|
import LinkedNotes from '@/components/LinkedNotes.vue'
|
||||||
import { filenameToNoteTitle } from '@/utils/noteTitle'
|
import { filenameToNoteTitle } from '@/utils/noteTitle'
|
||||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||||
|
import { useTitleNotes } from '@/hooks/useTitleNotes.hook'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'StackedNote',
|
name: 'StackedNote',
|
||||||
@@ -53,6 +54,7 @@ export default defineComponent({
|
|||||||
const { listenToClick } = useLinks('stacked-note', props.sha)
|
const { listenToClick } = useLinks('stacked-note', props.sha)
|
||||||
const className = computed(() => `stacked-note-${props.index}`)
|
const className = computed(() => `stacked-note-${props.index}`)
|
||||||
const titleClassName = computed(() => `title-${className.value}`)
|
const titleClassName = computed(() => `title-${className.value}`)
|
||||||
|
useTitleNotes(props.repo)
|
||||||
|
|
||||||
const { displayNoteOverlay } = useNoteOverlay(className.value, props.index)
|
const { displayNoteOverlay } = useNoteOverlay(className.value, props.index)
|
||||||
const displayedTitle = computed(() => filenameToNoteTitle(props.title))
|
const displayedTitle = computed(() => filenameToNoteTitle(props.title))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { useOverlay } from '@/hooks/useOverlay.hook'
|
|||||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||||
import { resolvePath } from '@/modules/repo/services/resolvePath'
|
import { resolvePath } from '@/modules/repo/services/resolvePath'
|
||||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
|
import { pathToNoteTitle } from '@/utils/noteTitle'
|
||||||
|
|
||||||
export const useNote = (containerClass: string) => {
|
export const useNote = (containerClass: string) => {
|
||||||
const store = useUserRepoStore()
|
const store = useUserRepoStore()
|
||||||
@@ -19,15 +20,7 @@ export const useNote = (containerClass: string) => {
|
|||||||
}
|
}
|
||||||
const filePath = store.files.find((file) => file.sha === note)?.path ?? ''
|
const filePath = store.files.find((file) => file.sha === note)?.path ?? ''
|
||||||
|
|
||||||
const fileNames = filePath.split('.')
|
obj[note] = pathToNoteTitle(filePath)
|
||||||
|
|
||||||
fileNames.pop()
|
|
||||||
obj[note] = fileNames
|
|
||||||
.join('.')
|
|
||||||
.split('/')
|
|
||||||
.filter((path) => !path.includes('README'))
|
|
||||||
.join('/')
|
|
||||||
.replaceAll('-', ' ')
|
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
}, {})
|
}, {})
|
||||||
|
|||||||
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])
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,2 +1,14 @@
|
|||||||
export const filenameToNoteTitle = (title: string) =>
|
export const filenameToNoteTitle = (title: string) =>
|
||||||
title.replaceAll('/', ' / ').replaceAll('-', ' ')
|
title.replaceAll('/', ' / ').replaceAll('-', ' ')
|
||||||
|
|
||||||
|
export const pathToNoteTitle = (path: string) => {
|
||||||
|
const fileNames = path.split('.')
|
||||||
|
|
||||||
|
fileNames.pop()
|
||||||
|
return fileNames
|
||||||
|
.join('.')
|
||||||
|
.split('/')
|
||||||
|
.filter((path) => !path.includes('README'))
|
||||||
|
.join('/')
|
||||||
|
.replaceAll('-', ' ')
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user