Skip to content

Commit

Permalink
feat: add titles for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jan 4, 2023
1 parent 9a167ee commit 377c015
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 7 deletions.
11 changes: 5 additions & 6 deletions composables/setups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { pwaInfo } from 'virtual:pwa-info'
import type { Link } from '@unhead/schema'
import type { Directions } from 'vue-i18n-routing'
import { buildInfo } from 'virtual:build-info'
import { APP_NAME } from '~/constants'
import type { LocaleObject } from '#i18n'

export function setupPageHeader() {
const i18n = useI18n()
const { locale, locales, t } = useI18n()

const link: Link[] = []

Expand All @@ -30,19 +29,19 @@ export function setupPageHeader() {
}
}

const localeMap = (i18n.locales.value as LocaleObject[]).reduce((acc, l) => {
const localeMap = (locales.value as LocaleObject[]).reduce((acc, l) => {
acc[l.code!] = l.dir ?? 'auto'
return acc
}, {} as Record<string, Directions>)

useHeadFixed({
htmlAttrs: {
lang: () => i18n.locale.value,
dir: () => localeMap[i18n.locale.value] ?? 'auto',
lang: () => locale.value,
dir: () => localeMap[locale.value] ?? 'auto',
},
titleTemplate: (title) => {
let titleTemplate = title ? `${title} | ` : ''
titleTemplate += APP_NAME
titleTemplate += t('app_name')
if (buildInfo.env !== 'release')
titleTemplate += ` (${buildInfo.env})`
return titleTemplate
Expand Down
2 changes: 1 addition & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
},
"featured_tags": {
"description": "人们可以在这些标签下浏览你的公共嘟文。",
"label": "精选的话题标签"
"label": "精选话题标签"
},
"label": "个人资料"
},
Expand Down
6 changes: 6 additions & 0 deletions pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ definePageMeta({
wideLayout: true,
})
const { t } = useI18n()
useHeadFixed({
title: () => t('nav.settings'),
})
const route = useRoute()
const isRootPath = computedEager(() => route.name === 'settings')
Expand Down
6 changes: 6 additions & 0 deletions pages/settings/about/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<script setup lang="ts">
import { buildInfo } from 'virtual:build-info'
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.about.label')} | ${t('nav.settings')}`,
})
let showCommit = $ref(buildInfo.env !== 'release' && buildInfo.env !== 'dev')
const builtTime = useFormattedDateTime(buildInfo.time)
Expand Down
8 changes: 8 additions & 0 deletions pages/settings/interface/index.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<script setup lang="ts">
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.interface.label')} | ${t('nav.settings')}`,
})
</script>

<template>
<MainContent back-on-small-screen>
<template #title>
Expand Down
8 changes: 8 additions & 0 deletions pages/settings/language/index.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<script setup lang="ts">
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.language.label')} | ${t('nav.settings')}`,
})
</script>

<template>
<MainContent back-on-small-screen>
<template #title>
Expand Down
8 changes: 8 additions & 0 deletions pages/settings/preferences/index.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<script setup lang="ts">
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.preferences.label')} | ${t('nav.settings')}`,
})
</script>

<template>
<MainContent back-on-small-screen>
<template #title>
Expand Down
6 changes: 6 additions & 0 deletions pages/settings/profile/appearance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ definePageMeta({
keepalive: false,
})
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.profile.appearance.title')} | ${t('nav.settings')}`,
})
const account = $computed(() => currentUser.value?.account)
const onlineSrc = $computed(() => ({
Expand Down
6 changes: 6 additions & 0 deletions pages/settings/profile/featured-tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
definePageMeta({
middleware: 'auth',
})
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.profile.featured_tags.label')} | ${t('nav.settings')}`,
})
</script>

<template>
Expand Down
6 changes: 6 additions & 0 deletions pages/settings/profile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
definePageMeta({
middleware: 'auth',
})
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.profile.label')} | ${t('nav.settings')}`,
})
</script>

<template>
Expand Down
6 changes: 6 additions & 0 deletions pages/settings/users/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
import { fileOpen } from 'browser-fs-access'
import type { UserLogin } from '~/types'
const { t } = useI18n()
useHeadFixed({
title: () => `${t('settings.users.label')} | ${t('nav.settings')}`,
})
const loggedInUsers = useUsers()
async function exportTokens() {
Expand Down

0 comments on commit 377c015

Please sign in to comment.