Skip to content

Commit

Permalink
chore: Linted codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hanyujie2002 committed Oct 26, 2024
1 parent 35c5b19 commit 9de3400
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 137 deletions.
2 changes: 1 addition & 1 deletion i18n.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineI18nConfig(() => ({
blog: '博客',
tags: '标签',
noResult: '未搜索到相关内容',
typeToSearch: '输入关键词进行搜索'
typeToSearch: '输入关键词进行搜索',
},
'zh-TW': {
about: '關於',
Expand Down
58 changes: 38 additions & 20 deletions layouts/admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
<nav
class="sticky top-0 z-40 flex h-[--header-height] flex-auto text-black backdrop-blur-2xl dark:text-slate-200"
>
<ul
class="mx-auto my-auto flex w-full max-w-screen-xl gap-4"
>
<ul class="mx-auto my-auto flex w-full max-w-screen-xl gap-4">
<li class="list-item">
<NuxtLink
class="flex flex-auto rounded px-4 py-2 md:ml-[10px] text-2xl font-extrabold transition-colors dark:text-slate-100"
class="flex flex-auto rounded px-4 py-2 text-2xl font-extrabold transition-colors md:ml-[10px] dark:text-slate-100"
to="/admin"
title="Home"
aria-label="Home Page"
Expand Down Expand Up @@ -75,20 +73,40 @@
class="size-10 transition-colors hover:text-yellow-500 active:text-yellow-400 sm:size-12 dark:hover:text-yellow-100 dark:active:text-yellow-200"
/>
</button>
<dialog ref="tokenDialogRef" class="absolute -translate-x-1/2 bg-white rounded">
<dialog
ref="tokenDialogRef"
class="absolute -translate-x-1/2 rounded bg-white"
>
<div class="flex flex-col">
<h2 class="w-36 text-xl font-thin text-center">Set Your Token</h2>
<div class="mx-2 mt-1">
<textarea v-model="githubToken" autofocus placeholder="Input Your Github Token" class="w-64 resize-none px-2 py-1 border rounded" />
</div>
<div class="flex mx-2 my-1 justify-between">
<button @click="handleTokenSet" class="bg-green-200 px-3 rounded font-light hover:brightness-95 active:brightness-90">OK</button>
<button @click="hideTokenDialog" class="bg-red-200 px-3 rounded font-light hover:brightness-95 active:brightness-90">Cancel</button>
</div>
<h2 class="w-36 text-center text-xl font-thin">
Set Your Token
</h2>
<div class="mx-2 mt-1">
<textarea
v-model="githubToken"
autofocus
placeholder="Input Your Github Token"
class="w-64 resize-none rounded border px-2 py-1"
/>
</div>
<div class="mx-2 my-1 flex justify-between">
<button
class="rounded bg-green-200 px-3 font-light hover:brightness-95 active:brightness-90"
@click="handleTokenSet"
>
OK
</button>
<button
class="rounded bg-red-200 px-3 font-light hover:brightness-95 active:brightness-90"
@click="hideTokenDialog"
>
Cancel
</button>
</div>
</div>
</dialog>
</li>
<li class="sm:max-xl:mr-2 my-auto list-item">
<li class="my-auto list-item sm:max-xl:mr-2">
<ColorModeSwitch />
</li>
<li class="my-auto mr-2 sm:hidden">
Expand Down Expand Up @@ -148,21 +166,21 @@ savedTheme.value = savedTheme.value || '';
const search = ref<string>('');
const results = ref();
const localePath = useLocalePath()
const localePath = useLocalePath();
const showTokenDialog = () => {
tokenDialogRef.value?.show();
}
};
const hideTokenDialog = () => {
tokenDialogRef.value?.close()
}
tokenDialogRef.value?.close();
};
const handleTokenSet = () => {
localStorage.setItem('github-token', githubToken.value);
githubToken.value = ''
githubToken.value = '';
hideTokenDialog();
}
};
const debouncedSearch = debounce(async (newSearch: string) => {
const searchTimeout = setTimeout(() => {
Expand Down
20 changes: 9 additions & 11 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@
<nav
class="sticky top-0 z-40 flex h-[--header-height] flex-auto text-black backdrop-blur-2xl dark:text-slate-200"
>
<ul
class="mx-auto my-auto flex w-full max-w-screen-xl gap-4"
>
<ul class="mx-auto my-auto flex w-full max-w-screen-xl gap-4">
<li class="list-item">
<NuxtLink
class="flex flex-auto rounded px-4 py-2 md:ml-[10px] text-2xl font-extrabold transition-colors dark:text-slate-100"
class="flex flex-auto rounded px-4 py-2 text-2xl font-extrabold transition-colors md:ml-[10px] dark:text-slate-100"
to="/"
title="Home"
aria-label="Home Page"
Expand Down Expand Up @@ -229,15 +227,15 @@
v-else-if="results?.length === 0 && isSearchEnded"
class="flex flex-grow items-center justify-center"
>
<span class="flex flex-grow justify-center text-center text-5xl"
>{{ $t('noResult') }}</span
>
<span class="flex flex-grow justify-center text-center text-5xl">{{
$t('noResult')
}}</span>
</div>
</div>
<div v-else class="flex flex-grow items-center justify-center">
<span class="flex flex-grow justify-center text-center text-5xl"
>{{ $t('typeToSearch') }}</span
>
<span class="flex flex-grow justify-center text-center text-5xl">{{
$t('typeToSearch')
}}</span>
</div>
</div>
</dialog>
Expand All @@ -261,7 +259,7 @@ const search = ref<string>('');
const dialogRef = ref<HTMLDialogElement>();
const results = ref();
const localePath = useLocalePath()
const localePath = useLocalePath();
const debouncedSearch = debounce(async (newSearch: string) => {
const searchTimeout = setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ export default defineNuxtConfig({
name: 'Vardar Example Site',
description: 'Example site of Vardar for demenstration',
},
});
});
91 changes: 55 additions & 36 deletions pages/admin/about.client.vue
Original file line number Diff line number Diff line change
@@ -1,73 +1,92 @@
<template>
<div class="flex flex-col w-[calc(100vw-10px)] justify-center items-center">
<div class="max-w-7xl w-full flex">
<div class="w-full flex mx-2 bg-gray-200 rounded-t">
<button @click="updateFile" class="bg-green-200 text-slate-800 hover:brightness-95 active:brightness-90 px-3 py-2 rounded my-2 ml-auto mr-2">Update</button>
<div class="flex w-[calc(100vw-10px)] flex-col items-center justify-center">
<div class="flex w-full max-w-7xl">
<div class="mx-2 flex w-full rounded-t bg-gray-200">
<button
class="my-2 ml-auto mr-2 rounded bg-green-200 px-3 py-2 text-slate-800 hover:brightness-95 active:brightness-90"
@click="updateFile"
>
Update
</button>
</div>
</div>
<div class="max-w-7xl px-2 grid grid-rows-2 xl:grid-rows-1 xl:grid-cols-2 max-h-[820px] overflow-auto">
<MonacoEditor lang="markdown" class="flex-grow max-h-[820px] border overflow-auto" v-model="inputText"
placeholder="Enter text to render" />
<MDC class="flex-grow max-h-[820px] border overflow-auto" :value="processedInputText"></MDC>
<div
class="grid max-h-[820px] max-w-7xl grid-rows-2 overflow-auto px-2 xl:grid-cols-2 xl:grid-rows-1"
>
<MonacoEditor
v-model="inputText"
lang="markdown"
class="max-h-[820px] flex-grow overflow-auto border"
placeholder="Enter text to render"
/>
<MDC
class="max-h-[820px] flex-grow overflow-auto border"
:value="processedInputText"
/>
</div>
</div>
</template>

<script setup>
definePageMeta({
layout: 'admin'
})
import { ref, onMounted } from 'vue';
import { ref, onMounted } from 'vue'
const inputText = ref('# loading...')
const route = useRoute()
const path = route.path
const stripedPath = path.replace(/^\/admin/, '');
const sha = ref('')
const articleUrl = 'https://api.github.com/repos/hanyujie2002/Vardar-Nuxt-Blog/contents/content' + '/about' + '.md?ref=main'
const token = localStorage.getItem('github-token')
definePageMeta({
layout: 'admin',
});
const inputText = ref('# loading...');
const sha = ref('');
const articleUrl =
'https://api.github.com/repos/hanyujie2002/Vardar-Nuxt-Blog/contents/content' +
'/about' +
'.md?ref=main';
const token = localStorage.getItem('github-token');
onMounted(async () => {
const response = await fetch(articleUrl, {
headers: {
'Authorization': `token ${token}`,
Authorization: `token ${token}`,
},
cache: 'no-cache'
})
cache: 'no-cache',
});
const data = await response.json()
const data = await response.json();
sha.value = data.sha;
const base64Content = data.content
const decodedContent = new TextDecoder('utf-8').decode(Uint8Array.from(atob(base64Content), c => c.charCodeAt(0)))
const base64Content = data.content;
const decodedContent = new TextDecoder('utf-8').decode(
Uint8Array.from(atob(base64Content), (c) => c.charCodeAt(0))
);
inputText.value = decodedContent
})
inputText.value = decodedContent;
});
const processedInputText = computed(() => inputText.value.length > 0 ? inputText.value : 'No content yet');
const processedInputText = computed(() =>
inputText.value.length > 0 ? inputText.value : 'No content yet'
);
const updateFile = async () => {
const updatedContent = new TextEncoder().encode(inputText.value);
const base64Content = btoa(String.fromCharCode(...new Uint8Array(updatedContent)))
const base64Content = btoa(
String.fromCharCode(...new Uint8Array(updatedContent))
);
const response = await fetch(articleUrl, {
method: 'PUT',
headers: {
'Authorization': `token ${token}`,
Authorization: `token ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'Test: Updating blog content',
content: base64Content,
sha: sha.value,
})
})
}),
});
if (response.ok) {
console.log('File updated successfully!')
console.log('File updated successfully!');
} else {
console.error('File update failed', response.statusText)
console.error('File update failed', response.statusText);
}
}
};
</script>

Loading

0 comments on commit 9de3400

Please sign in to comment.