Skip to content

Commit 453703b

Browse files
committed
feat: add custom website setting
1 parent 868e78d commit 453703b

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default defineNuxtConfig({
1616
themeColor: process.env.NUXT_PUBLIC_THEME_COLOR || '#1e40af',
1717
favicon: process.env.NUXT_PUBLIC_FAVICON || '/_favicon.ico',
1818
faviconPng: process.env.NUXT_PUBLIC_FAVICON_PNG || '/_favicon.png',
19+
website: process.env.NUXT_PUBLIC_WEBSITE || '',
1920
github: process.env.NUXT_PUBLIC_GITHUB || '',
2021
instagram: process.env.NUXT_PUBLIC_INSTAGRAM || '',
2122
twitter: process.env.NUXT_PUBLIC_TWITTER || '',

src/components/NavBar.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
class="grid grid-cols-4 sm:flex items-center space-x-2 sm:space-x-3 md:space-x-4 light:opacity-70"
5656
:style="`color: ${settings.themeColor || $config.public.themeColor || '#ffffff'}`"
5757
>
58+
<NuxtLink
59+
v-if="settings.website || $config.public.website"
60+
:to="`${settings.website || $config.public.website}`"
61+
target="_blank"
62+
>
63+
<UIcon
64+
name="mdi:web"
65+
class="size-5 sm:size-6"
66+
/>
67+
</NuxtLink>
5868
<NuxtLink
5969
v-if="settings.github || $config.public.github"
6070
:to="`https://github.com/${settings.github || $config.public.github}`"

src/components/SettingsForm.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@
188188
<h3 class="text-lg font-semibold mb-4">Social Media</h3>
189189

190190
<div class="space-y-4">
191+
<UFormField
192+
label="Website"
193+
name="website"
194+
help="Your personal website URL"
195+
>
196+
<UInput
197+
v-model="state.website"
198+
placeholder="https://example.com"
199+
class="w-full"
200+
:disabled="loading"
201+
icon="mdi:web"
202+
/>
203+
</UFormField>
204+
191205
<UFormField
192206
label="GitHub"
193207
name="github"
@@ -430,6 +444,7 @@ const state = reactive<SettingsInput>({
430444
themeColor: '',
431445
favicon: '',
432446
faviconPng: '',
447+
website: '',
433448
github: '',
434449
twitter: '',
435450
instagram: '',
@@ -460,6 +475,15 @@ const isValidUrl = (value: string, allowedHosts: string[]): boolean => {
460475
};
461476
462477
// Computed properties for social media URLs
478+
const websiteUrl = computed(() => {
479+
if (!state.website) return '';
480+
const allowedHosts = ['example.com', 'myblog.com'];
481+
if (isValidUrl(state.website, allowedHosts)) {
482+
return state.website.startsWith('http') ? state.website : `https://${state.website}`;
483+
}
484+
return '';
485+
});
486+
463487
const githubUrl = computed(() => {
464488
if (!state.github) return '';
465489
const allowedHosts = ['github.com'];

src/composables/useDatabase.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export function useSettings() {
107107
themeColor?: string;
108108
favicon?: string;
109109
faviconPng?: string;
110+
website?: string;
110111
github?: string;
111112
twitter?: string;
112113
instagram?: string;

src/server/api/settings.get.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default defineEventHandler(async (_) => {
1212
const favicon = (await kv.get<string>('nuxtpress:setting:favicon')) || config.public.favicon;
1313
const faviconPng =
1414
(await kv.get<string>('nuxtpress:setting:favicon_png')) || config.public.faviconPng;
15+
const website = (await kv.get<string>('nuxtpress:setting:website')) || config.public.website;
1516
const github = (await kv.get<string>('nuxtpress:setting:github')) || config.public.github;
1617
const twitter = (await kv.get<string>('nuxtpress:setting:twitter')) || config.public.twitter;
1718
const instagram =
@@ -30,6 +31,7 @@ export default defineEventHandler(async (_) => {
3031
author,
3132
favicon,
3233
faviconPng,
34+
website,
3335
github,
3436
twitter,
3537
instagram,

src/server/api/settings.post.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default defineEventHandler(async (event) => {
1414
themeColor,
1515
favicon,
1616
faviconPng,
17+
website,
1718
github,
1819
twitter,
1920
instagram,
@@ -114,6 +115,19 @@ export default defineEventHandler(async (event) => {
114115
}
115116
}
116117

118+
if (website) {
119+
// Validate website URL - must start with http:// or https://
120+
const urlPattern = /^(https?:\/\/)/;
121+
if (!urlPattern.test(website)) {
122+
throw createError({
123+
statusCode: 400,
124+
statusMessage: 'Website must start with http:// or https://'
125+
});
126+
}
127+
128+
await kv.set('nuxtpress:setting:website', website);
129+
}
130+
117131
if (github) {
118132
let github0 = github;
119133
if (github.includes('https://') || github.includes('http://')) {

src/shared/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const settingsSchema = z.object({
3131
.optional(),
3232
favicon: z.string().optional(),
3333
faviconPng: z.string().optional(),
34+
website: z.url('Must be a valid URL').optional().or(z.literal('')),
3435
github: z.string().optional(),
3536
twitter: z.string().optional(),
3637
instagram: z.string().optional(),

0 commit comments

Comments
 (0)