Skip to content

Commit

Permalink
Merge pull request #111 from mirumirumi/dev
Browse files Browse the repository at this point in the history
release
  • Loading branch information
mirumirumi authored Jun 15, 2024
2 parents 40bf917 + 617c40b commit aa7f153
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"useTemplate": "off",
"noUselessElse": "off",
"useImportType": "off",
"noUnusedTemplateLiteral": "off"
"noUnusedTemplateLiteral": "off",
"useShorthandFunctionType": "off"
},
"complexity": {
"noForEach": "off"
Expand Down
79 changes: 56 additions & 23 deletions src/components/modules/TheCategoryMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,47 @@
<Transition name="fadedown" appear>
<div class="category_menu" v-if="_isShown">
<ul>
<li v-for="category in categories" :class="{ 'others_li_wrap': category.slug === 'others' }" :key="category.name">
<div v-if="category.slug === 'others'" class="others_wrap" @mouseenter="(isShownOthers = true)" @mouseleave="(isShownOthers = false)" @click.stop>
<li
v-for="category in categories"
:class="{ others_li_wrap: category.slug === 'others' }"
:key="category.name"
>
<div
v-if="category.slug === 'others'"
class="others_wrap"
@mouseenter="isShownOthers = true"
@mouseleave="isShownOthers = false"
@click.stop
>
<div class="others_title">
<span :class="{ 'current': category.current }">
<span :class="{ current: category.current }">
{{ category.name }}
</span>
<PartsSvgIcon :icon="'angle_down'" :color="'var(--color-gray)'" :class="{ 'rotate': isShownOthers }" />
<PartsSvgIcon
:icon="'angle_down'"
:color="'var(--color-gray)'"
:class="{ rotate: isShownOthers }"
/>
</div>
<Transition name="fade" appear>
<ul v-if="isShownOthers">
<li v-for="other in others" :key="other.name">
<NuxtLink :to="`/category/${other.slug}/`" :class="{ 'current': other.current }" @click="interruptChoose">
<NuxtLink
:to="`/category/${other.slug}/`"
:class="{ current: other.current }"
@click="interruptChoose"
>
{{ other.name }}
</NuxtLink>
</li>
</ul>
</Transition>
</div>
<NuxtLink v-else :to="`/category/${category.slug}/`" :class="{ 'current': category.current }">
<NuxtLink
v-else
:to="`/category/${category.slug}/`"
:class="{ current: category.current }"
>
{{ category.name }}
</NuxtLink>
</li>
Expand All @@ -44,7 +66,7 @@ const p = defineProps<{
}>()
const emit = defineEmits<{
(e: "interruptChoose" ): void
(e: "interruptChoose"): void
}>()
const route = useRoute()
Expand Down Expand Up @@ -73,31 +95,40 @@ const others: Category[] = [
await setIsCurrentCategory()
watch(() => p.isShown, () => {
_isShown.value = p.isShown
})
watch(
() => p.isShown,
() => {
_isShown.value = p.isShown
}
)
watch(route, async () => {
await setIsCurrentCategory()
})
watch(
() => route.path,
async () => {
await setIsCurrentCategory()
}
)
async function setIsCurrentCategory(): Promise<void> {
let categorySlug = ""
if (route.params.categoryName) {
// In category page
categorySlug = route.path.replace("/category/", "")
categorySlug = route.path.replace(/\/category\/(.*?)\//gim, "$1")
} else if (route.params.post) {
// In post page
const pagePath = route.path.replace("/", "")
// https://github.com/nuxt/nuxt/discussions/??? (The page is gone... (cause by unifying repos for Nuxt 2/3))
categorySlug = await $fetch<string>(`/mirumi/category_slug_with_post_slug/${pagePath}`, {
baseURL: appConfig.baseURL,
parseResponse: JSON.parse,
})
const pagePath = route.path.replaceAll("/", "")
// https://github.com/nuxt/nuxt/discussions/??? (The page is gone... (cause by unifying repos for Nuxt 2~3))
categorySlug = await $fetch<string>(
`/mirumi/category_slug_with_post_slug/${pagePath}`,
{
baseURL: appConfig.baseURL,
parseResponse: JSON.parse,
}
)
}
for (const category of categories) {
Expand All @@ -111,7 +142,7 @@ async function setIsCurrentCategory(): Promise<void> {
for (const other of others) {
if (categorySlug === other.slug) {
other.current = true
categories.slice(-1)[0].current = true // `その他`
categories.slice(-1)[0].current = true // `その他`
} else {
other.current = false
}
Expand Down Expand Up @@ -175,7 +206,9 @@ const interruptChoose = () => {
}
}
}
a, span, .others_wrap > .others_title > span {
a,
span,
.others_wrap > .others_title > span {
display: block;
color: var(--color-gray);
text-decoration: none;
Expand Down
24 changes: 6 additions & 18 deletions src/pages/[post].vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,13 @@ onMounted(async () => {
const slug = route.params.post as string
const { data } = await useFetch(`/mirumi/post_data/${slug}`, {
baseURL: appConfig.baseURL,
retry: 100,
retryDelay: 10_000,
})
// biome-ignore lint:
let post: any = undefined
do {
post = undefined
const { data } = await useFetch(`/mirumi/post_data/${slug}`, {
baseURL: appConfig.baseURL,
retry: 100,
retryDelay: 10_000,
})
// biome-ignore lint: Hack for JSON parse error (unexpected token)
post = JSON.parse(JSON.stringify(data.value as any))
if (typeof post === "string") {
console.log(`Failed to fetch: /${slug}`)
await delay(10_000)
}
} while (typeof post === "string")
const post = data.value as any
const thumbnailUrl = post.thumbnail_url.replace(/\.(png|jpg|jpeg)$/gim, ".webp")
Expand Down

0 comments on commit aa7f153

Please sign in to comment.