1
mirror of https://github.com/interstellar750/hexo_s synced 2024-10-13 14:38:39 +08:00

config: ⬆ sync & customize

This commit is contained in:
Hubert 2023-01-31 11:27:51 +08:00
parent 6f821033bb
commit 3cbc6756bc
Signed by: trle5
GPG Key ID: 2935B4DE0D6F7720
3 changed files with 48 additions and 18 deletions

1
.gitignore vendored
View File

@ -20,5 +20,6 @@ pnpm-debug.log*
# temp file
src/routes/**/+page.svelte.md
src/routes/**/+page.md
src/static
*.config.js
urara.js

View File

@ -95,12 +95,13 @@
<p class="flex-1 text-left text-base-content group-hover:text-primary-content transition-color">
{text ?? name}
</p>
<div class="flex-none m-auto flex gap-1">
<div class="bg-primary w-2 h-4 rounded" />
<div class="bg-secondary w-2 h-4 rounded" />
<div class="bg-accent w-2 h-4 rounded" />
<div class="bg-neutral w-2 h-4 rounded" />
</div>
<div class="grid grid-cols-4 gap-0.5 m-auto">
{#each ['bg-primary', 'bg-secondary', 'bg-accent', 'bg-neutral'] as bg}
<div class={`${bg} w-1 h-2 rounded-btn`} />
{/each}
{#each ['bg-info', 'bg-success', 'bg-warning', 'bg-error'] as bg}
<div class={`${bg} w-1 h-1 rounded-btn`} />
{/each}
</button>
{/each}
</ul>

View File

@ -9,11 +9,15 @@ import chokidar from 'chokidar'
import chalk from 'chalk'
const config = {
extensions: ['md', 'svelte'],
extensions: {
posts: ['md', 'svelte'],
images: ['jpg', 'png', 'webp', 'avif']
},
images: [''],
catch: ['ENOENT', 'EEXIST']
}
const check = (ext: string) => (config.extensions.includes(ext) ? 'src/routes' : 'static')
const check = (ext: string) => (config.extensions.posts.includes(ext) ? 'src/routes' : 'static')
const log = (color: string, msg: string, dest?: string | Error) =>
console.log(
@ -37,16 +41,28 @@ const error = (err: { code: string; message: unknown }) => {
}
const cpFile = (src: string, { stat = 'copy', dest = path.join(check(path.parse(src).ext.slice(1)), src.slice(6)) } = {}) =>
fs
.copyFile(src, dest)
.then(() => log('green', `${stat} file`, dest))
.catch(error)
config.extensions.images.includes(path.parse(src).ext.slice(1))
? fs
.copyFile(src, path.join('src/static', src.slice(6)))
.then(() => fs.copyFile(src, path.join('static', src.slice(6))))
.then(() => log('green', `${stat} file`, dest))
.catch(error)
: fs
.copyFile(src, dest)
.then(() => log('green', `${stat} file`, dest))
.catch(error)
const rmFile = (src: string, { dest = path.join(check(path.parse(src).ext.slice(1)), src.slice(6)) } = {}) =>
fs
.rm(dest)
.then(() => log('yellow', 'remove file', dest))
.catch(error)
config.extensions.images.includes(path.parse(src).ext.slice(1))
? fs
.rm(path.join('src/static', src.slice(6)))
.then(() => fs.rm(path.join('static', src.slice(6))))
.then(() => log('yellow', 'remove file', dest))
.catch(error)
: fs
.rm(dest)
.then(() => log('yellow', 'remove file', dest))
.catch(error)
const cpDir = (src: string) =>
fs.readdir(src, { withFileTypes: true }).then(files =>
@ -63,7 +79,12 @@ const cpDir = (src: string) =>
})
)
const mkDir = (src: string, { dest = [path.join('src/routes', src.slice(6)), path.join('static', src.slice(6))] } = {}) => {
const mkDir = (
src: string,
{
dest = [path.join('src/routes', src.slice(6)), path.join('static', src.slice(6)), path.join('src/static', src.slice(6))]
} = {}
) => {
dest.forEach(path =>
fs
.mkdir(path)
@ -72,7 +93,12 @@ const mkDir = (src: string, { dest = [path.join('src/routes', src.slice(6)), pat
)
}
const rmDir = (src: string, { dest = [path.join('src/routes', src.slice(6)), path.join('static', src.slice(6))] } = {}) => {
const rmDir = (
src: string,
{
dest = [path.join('src/routes', src.slice(6)), path.join('static', src.slice(6)), path.join('src/static', src.slice(6))]
} = {}
) => {
dest.forEach(path =>
fs
.rm(path, { force: true, recursive: true })
@ -91,12 +117,14 @@ const cleanDir = (src: string) =>
const build = () => {
mkDir('static', { dest: ['static'] })
mkDir('src/static', { dest: ['src/static'] })
cpDir('urara')
}
const clean = () => {
cleanDir('urara')
rmDir('static', { dest: ['static'] })
rmDir('src/static', { dest: ['src/static'] })
}
switch (process.argv[2]) {