✨ (path) create a resolve path service to manage …
resolve path like ../..
This commit is contained in:
@@ -3,11 +3,11 @@ import markdownItClass from '@toycode/markdown-it-class'
|
||||
|
||||
const md = new MarkdownIt().use(markdownItClass, {
|
||||
h1: ['title', 'is-1'],
|
||||
h2: ['subtitle', 'is-2'],
|
||||
h3: ['subtitle', 'is-3'],
|
||||
h4: ['subtitle', 'is-4'],
|
||||
h5: ['subtitle', 'is-5'],
|
||||
h6: ['subtitle', 'is-6'],
|
||||
h2: ['title', 'is-2'],
|
||||
h3: ['title', 'is-3'],
|
||||
h4: ['title', 'is-4'],
|
||||
h5: ['title', 'is-5'],
|
||||
h6: ['title', 'is-6'],
|
||||
table: ['table', 'is-striped', 'is-hoverable', 'is-fullwidth']
|
||||
})
|
||||
|
||||
|
||||
@@ -15,13 +15,7 @@ import { useOverlay } from '@/hooks/useOverlay.hook'
|
||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||
import { useRepo } from '@/hooks/useRepo.hook'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const sanitizePath = (path: string) => {
|
||||
if (path.startsWith('./')) {
|
||||
return decodeURIComponent(path.replace('./', ''))
|
||||
}
|
||||
return decodeURIComponent(path)
|
||||
}
|
||||
import { resolvePath } from '@/modules/repo/services/resolvePath'
|
||||
|
||||
export const useNote = (
|
||||
containerClass: string,
|
||||
@@ -59,19 +53,9 @@ export const useNote = (
|
||||
({ path, currentNoteSHA }) => {
|
||||
const currentFile = tree.value.find((file) => file.sha === currentNoteSHA)
|
||||
|
||||
const absolutePathArray = currentFile?.path?.split('/') ?? []
|
||||
absolutePathArray?.pop()
|
||||
const absolutePath = absolutePathArray.join('/')
|
||||
const finalPath = resolvePath(currentFile?.path ?? '', path)
|
||||
|
||||
const finalPath = absolutePath
|
||||
? `${sanitizePath(absolutePath)}/${sanitizePath(path)}`
|
||||
: sanitizePath(path)
|
||||
|
||||
const relativePath = sanitizePath(path)
|
||||
|
||||
const file = tree.value.find(
|
||||
(file) => file.path === finalPath || file.path === relativePath
|
||||
)
|
||||
const file = tree.value.find((file) => file.path === finalPath)
|
||||
|
||||
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
|
||||
scrollToFocusedNote(file?.sha)
|
||||
|
||||
32
src/modules/repo/services/resolvePath.ts
Normal file
32
src/modules/repo/services/resolvePath.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
const sanitizePath = (path: string) => {
|
||||
if (path.startsWith('./')) {
|
||||
return decodeURIComponent(path.replace('./', ''))
|
||||
}
|
||||
return decodeURIComponent(path)
|
||||
}
|
||||
|
||||
const removeNoteFilename = (pathNote: string) => {
|
||||
const path = pathNote.split('/')
|
||||
path.pop()
|
||||
|
||||
return sanitizePath(path.join('/'))
|
||||
}
|
||||
|
||||
export const resolvePath = (
|
||||
currentAbsolutePathNote: string,
|
||||
pathToResolve: string
|
||||
) => {
|
||||
let currentAbsolutePath = removeNoteFilename(currentAbsolutePathNote)
|
||||
pathToResolve = sanitizePath(pathToResolve)
|
||||
|
||||
while (pathToResolve.startsWith('../')) {
|
||||
const adjustedAbsolutePath = currentAbsolutePath.split('/')
|
||||
adjustedAbsolutePath.pop()
|
||||
currentAbsolutePath = adjustedAbsolutePath.join('/')
|
||||
pathToResolve = pathToResolve.replace('../', '')
|
||||
}
|
||||
|
||||
return currentAbsolutePath
|
||||
? `${currentAbsolutePath}/${pathToResolve}`
|
||||
: pathToResolve
|
||||
}
|
||||
@@ -9,8 +9,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
|
||||
import { defineAsyncComponent, defineComponent, toRefs } from 'vue'
|
||||
import { defineAsyncComponent, defineComponent, onMounted, toRefs } from 'vue'
|
||||
|
||||
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
||||
|
||||
@@ -32,6 +33,11 @@ export default defineComponent({
|
||||
refProps.user,
|
||||
refProps.repo
|
||||
)
|
||||
const { resetStackedNotes } = useQueryStackedNotes()
|
||||
|
||||
onMounted(() => {
|
||||
resetStackedNotes()
|
||||
})
|
||||
|
||||
return {
|
||||
content
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
|
||||
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
|
||||
import { defineAsyncComponent, defineComponent, toRefs } from 'vue'
|
||||
import { defineAsyncComponent, defineComponent, onMounted, toRefs } from 'vue'
|
||||
|
||||
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
|
||||
|
||||
@@ -32,6 +33,11 @@ export default defineComponent({
|
||||
refProps.user,
|
||||
refProps.repo
|
||||
)
|
||||
const { resetStackedNotes } = useQueryStackedNotes()
|
||||
|
||||
onMounted(() => {
|
||||
resetStackedNotes()
|
||||
})
|
||||
|
||||
return {
|
||||
content
|
||||
|
||||
Reference in New Issue
Block a user