diff --git a/src/router/router.ts b/src/router/router.ts index 37d3d1e..49be82c 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -31,7 +31,7 @@ const routes: Array = [ component: () => import("@/views/PublicNoteListByDidView.vue"), }, { - path: "/pub/:did/:rkey", + path: "/pub/:did/:rkey/:slug?", name: "PublicNoteView", props: true, component: () => import("@/views/PublicNoteView.vue"), diff --git a/src/utils/slugify.ts b/src/utils/slugify.ts new file mode 100644 index 0000000..4909f82 --- /dev/null +++ b/src/utils/slugify.ts @@ -0,0 +1,9 @@ +export function slugify(text: string): string { + return text + .toLowerCase() + .normalize("NFD") + .replace(/[\u0300-\u036f]/g, "") + .replace(/[^a-z0-9]+/g, "-") + .replace(/-+/g, "-") + .replace(/^-|-$/g, "") +} diff --git a/src/views/PublicNoteListByDidView.vue b/src/views/PublicNoteListByDidView.vue index 4060350..2fac25e 100644 --- a/src/views/PublicNoteListByDidView.vue +++ b/src/views/PublicNoteListByDidView.vue @@ -2,6 +2,7 @@ import BackButton from "@/components/BackButton.vue" import { usePublicNoteList } from "@/hooks/usePublicNoteList.hook" import { getAuthor } from "@/modules/atproto/getAuthor" +import { slugify } from "@/utils/slugify" import { computedAsync } from "@vueuse/core" import { computed } from "vue" import { vInfiniteScroll } from "@vueuse/components" @@ -31,7 +32,7 @@ const author = computedAsync(async () => getAuthor(did.value)) {{ note.title }} import BackButton from "@/components/BackButton.vue" import { usePublicNoteList } from "@/hooks/usePublicNoteList.hook" +import { slugify } from "@/utils/slugify" import { vInfiniteScroll } from "@vueuse/components" const { notes, isLoading, canLoadMore, onLoadMore, getAuthor } = @@ -24,7 +25,7 @@ const { notes, isLoading, canLoadMore, onLoadMore, getAuthor } = {{ note.title }}() +const props = defineProps<{ did: string; rkey: string; slug?: string }>() +const router = useRouter() const did = computed(() => props.did) const rkey = computed(() => props.rkey) @@ -31,6 +34,15 @@ const noteRecord = computedAsync(async () => ) watch(noteRecord, () => { + if ( + noteRecord.value?.value.title && + props.slug && + props.slug !== slugify(noteRecord.value.value.title) + ) { + router.replace({ name: "SpaceCowboy" }) + return + } + if (noteRecord.value?.value.fontFamily) { downloadFont(noteRecord.value.value.fontFamily) }