Skip to content

Commit

Permalink
記事タイトルに "/" が入っているときリンクが動作しない不具合を修正した
Browse files Browse the repository at this point in the history
  • Loading branch information
kamikoloss committed Feb 9, 2024
1 parent 649aa50 commit da1b164
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scrapbox-nuxt-blog/components/Article.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const hasLineQuote = (index) => lines[index]?.nodes?.some(node => node.type ===
<template #header>
<!-- タイトル -->
<h2 class="text-xl font-bold my-2">
<NuxtLink :to="`/${page.title.replace(/ /g, '_')}`">{{ page.title }}</NuxtLink>
<NuxtLink :to="`/${escapeArticleTitle(page.title)}`">{{ page.title }}</NuxtLink>
</h2>
<!-- 日時 -->
<div
Expand Down
2 changes: 1 addition & 1 deletion scrapbox-nuxt-blog/components/Card.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
const props = defineProps({ page: Object })
const linkTo = props.page?.title.replace(/ /g, '_')
const linkTo = escapeArticleTitle(props.page?.title)
const appConfig = useAppConfig()
</script>
Expand Down
2 changes: 1 addition & 1 deletion scrapbox-nuxt-blog/pages/[title].vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const appConfig = useAppConfig()
const route = useRoute()
const { title: routeTitle } = route.params
const articleTitle = routeTitle.replace(/_/g, ' ')
const articleTitle = unescapeArticleTitle(routeTitle)
useHead({
title: `${appConfig.blogTitle} - ${articleTitle}`,
Expand Down
2 changes: 1 addition & 1 deletion scrapbox-nuxt-blog/pages/history/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const { data: pages } = await useAsyncData('history', () => {
<li v-for="page of pages" class="my-2">
<Date :unix-time="page.created" :show-time="false" class="mr-2" />
<NuxtLink
:to="`/${page.title.replace(/ /g, '_')}`"
:to="`/${escapeArticleTitle(page.title)}`"
class="text-text-link"
>
{{ page.title }}
Expand Down
9 changes: 9 additions & 0 deletions scrapbox-nuxt-blog/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 記事のタイトルをエスケープする
export const escapeArticleTitle = (title: string): string => {
return title.replace(/ /g, '_').replace(/\//g, '%2F')
}

// 記事のタイトルをアンエスケープする
export const unescapeArticleTitle = (title: string): string => {
return title.replace(/_/g, ' ').replace(/%2F/g, '/')
}

0 comments on commit da1b164

Please sign in to comment.