Skip to content

Commit

Permalink
style: format with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
lxchapu committed May 12, 2024
1 parent f3d29b9 commit 9d0066e
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 115 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
extends: ['@commitlint/config-conventional']
extends: ['@commitlint/config-conventional'],
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
"simple-git-hooks": {
"commit-msg": "pnpm exec commitlint --edit $1"
}
}
}
46 changes: 23 additions & 23 deletions scripts/new-friend.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import { input } from "@inquirer/prompts";
import fs from "fs";
import path from "path";
import { isFileNameSafe } from "./utils.js";
import { input } from '@inquirer/prompts'
import fs from 'fs'
import path from 'path'
import { isFileNameSafe } from './utils.js'

function getFriendFullPath(fileName) {
return path.join("./src/content/friends", `${fileName}.yaml`);
return path.join('./src/content/friends', `${fileName}.yaml`)
}

const fileName = await input({
message: "请输入文件名称",
message: '请输入文件名称',
validate: (value) => {
if (!isFileNameSafe(value)) {
return "文件名只能包含字母、数字和连字符";
return '文件名只能包含字母、数字和连字符'
}
const fullPath = getFriendFullPath(value);
const fullPath = getFriendFullPath(value)
if (fs.existsSync(fullPath)) {
return `${fullPath} 已存在`;
return `${fullPath} 已存在`
}
return true;
return true
},
});
})

const title = await input({
message: "请输入标题",
});
message: '请输入标题',
})
const description = await input({
message: "请输入描述",
});
message: '请输入描述',
})
const link = await input({
message: "请输入地址",
});
message: '请输入地址',
})
const avatar = await input({
message: "请输入头像地址",
});
message: '请输入头像地址',
})

const content = `title: ${title}
description: ${description}
link: ${link}
avatar: ${avatar}
`;
`

const fullPath = getFriendFullPath(fileName);
fs.writeFileSync(fullPath, content);
console.log(`${fullPath} 创建成功`);
const fullPath = getFriendFullPath(fileName)
fs.writeFileSync(fullPath, content)
console.log(`${fullPath} 创建成功`)
34 changes: 17 additions & 17 deletions scripts/new-post.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { input } from "@inquirer/prompts";
import fs from "fs";
import path from "path";
import { isFileNameSafe } from "./utils.js";
import { input } from '@inquirer/prompts'
import fs from 'fs'
import path from 'path'
import { isFileNameSafe } from './utils.js'

function getPostFullPath(fileName) {
return path.join("./src/content/posts", `${fileName}.md`);
return path.join('./src/content/posts', `${fileName}.md`)
}

const fileName = await input({
message: "请输入文件名称",
message: '请输入文件名称',
validate: (value) => {
if (!isFileNameSafe(value)) {
return "文件名只能包含字母、数字和连字符";
return '文件名只能包含字母、数字和连字符'
}
const fullPath = getPostFullPath(value);
const fullPath = getPostFullPath(value)
if (fs.existsSync(fullPath)) {
return `${fullPath} 已存在`;
return `${fullPath} 已存在`
}
return true;
return true
},
});
})

const title = await input({
message: "请输入文章标题",
});
message: '请输入文章标题',
})

const content = `---
title: ${title}
Expand All @@ -32,8 +32,8 @@ tags: []
comments: true
draft: false
---
`;
`

const fullPath = getPostFullPath(fileName);
fs.writeFileSync(fullPath, content);
console.log(`${fullPath} 创建成功`);
const fullPath = getPostFullPath(fileName)
fs.writeFileSync(fullPath, content)
console.log(`${fullPath} 创建成功`)
46 changes: 23 additions & 23 deletions scripts/new-project.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import { input } from "@inquirer/prompts";
import fs from "fs";
import path from "path";
import { isFileNameSafe } from "./utils.js";
import { input } from '@inquirer/prompts'
import fs from 'fs'
import path from 'path'
import { isFileNameSafe } from './utils.js'

function getProjectFullPath(fileName) {
return path.join("./src/content/projects", `${fileName}.yaml`);
return path.join('./src/content/projects', `${fileName}.yaml`)
}

const fileName = await input({
message: "请输入文件名称",
message: '请输入文件名称',
validate: (value) => {
if (!isFileNameSafe(value)) {
return "文件名只能包含字母、数字和连字符";
return '文件名只能包含字母、数字和连字符'
}
const fullPath = getProjectFullPath(value);
const fullPath = getProjectFullPath(value)
if (fs.existsSync(fullPath)) {
return `${fullPath} 已存在`;
return `${fullPath} 已存在`
}
return true;
return true
},
});
})

const title = await input({
message: "请输入项目名称",
});
message: '请输入项目名称',
})
const description = await input({
message: "请输入项目描述",
});
message: '请输入项目描述',
})
const link = await input({
message: "请输入项目地址",
});
message: '请输入项目地址',
})
const image = await input({
message: "请输入预览图片地址",
});
message: '请输入预览图片地址',
})

const content = `title: ${title}
description: ${description}
link: ${link}
image: ${image}
`;
`

const fullPath = getProjectFullPath(fileName);
fs.writeFileSync(fullPath, content);
console.log(`${fullPath} 创建成功`);
const fullPath = getProjectFullPath(fileName)
fs.writeFileSync(fullPath, content)
console.log(`${fullPath} 创建成功`)
2 changes: 1 addition & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isFileNameSafe(fileName) {
return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(fileName);
return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(fileName)
}
4 changes: 2 additions & 2 deletions src/content/posts/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ All work and no play makes Jack a dull boy.
The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a `footer` or `cite` element, and optionally with in-line changes such as annotations and abbreviations.

> Tiam, ad mint andaepu dandae nostion secatur sequo quae.
> **Note** that you can use *Markdown syntax* within a blockquote.
> **Note** that you can use _Markdown syntax_ within a blockquote.
嵌套的引用

Expand Down Expand Up @@ -95,7 +95,7 @@ The blockquote element represents content that is quoted from another source, op

| Italics | Bold | Code |
| --------- | -------- | ------ |
| *italics* | **bold** | `code` |
| _italics_ | **bold** | `code` |

## 代码块

Expand Down
2 changes: 1 addition & 1 deletion src/content/spec/projects.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
title: 项目
description: 这些是我创建或参与的项目,如果你感兴趣不妨去给个 Star。
---
---
4 changes: 2 additions & 2 deletions src/plugins/rehypeCodeHighlight.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import rehypeShiki from '@shikijs/rehype'

export const rehypeCodeHighlight = [
export const rehypeCodeHighlight = [
rehypeShiki,
{
themes: {
Expand All @@ -9,4 +9,4 @@ export const rehypeCodeHighlight = [
},
defaultColor: false,
},
]
]
6 changes: 1 addition & 5 deletions src/plugins/rehypeTableBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { visit } from 'unist-util-visit'
export function rehypeTableBlock() {
return function (tree) {
visit(tree, { tagName: 'table' }, (node, index, parent) => {
const divWrapper = h(
'div',
{ class: 'table-block' },
[node]
)
const divWrapper = h('div', { class: 'table-block' }, [node])
parent.children[index] = divWrapper
})
}
Expand Down
60 changes: 25 additions & 35 deletions src/plugins/remarkSpoiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ export function remarkSpoiler() {
const self = this
const data = self.data()

const micromarkExtensions =
data.micromarkExtensions || (data.micromarkExtensions = [])
const fromMarkdownExtensions =
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = [])
const fromMarkdownExtensions = data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])

micromarkExtensions.push(spoilerSyntax())
fromMarkdownExtensions.push(spoilerFromMarkdown())
Expand All @@ -16,23 +14,18 @@ export function remarkSpoiler() {
function spoilerSyntax() {
return {
text: {
[codes.verticalBar]: spoilerConstruct
}
[codes.verticalBar]: spoilerConstruct,
},
}
}

const spoilerConstruct = { name: 'spoiler', tokenize: spoilerTokenize }
const markerConstruct = { tokenize: markerTokenize, partial: true }


function spoilerTokenize(effects, ok, nok) {
function start() {
effects.enter('spoiler')
return effects.attempt(
markerConstruct,
contentStart,
nok
)
return effects.attempt(markerConstruct, contentStart, nok)
}

function contentStart() {
Expand All @@ -43,29 +36,25 @@ function spoilerTokenize(effects, ok, nok) {
}

function content() {
return effects.check(
markerConstruct,
contentEnd,
consumeData
)
return effects.check(markerConstruct, contentEnd, consumeData)
}

function consumeData(code) {
if (code === codes.eof || code < codes.horizontalTab) {
return nok;
return nok
}
effects.consume(code);
return content;
effects.consume(code)
return content
}

function contentEnd() {
effects.exit(types.chunkText);
return effects.attempt(markerConstruct, after, nok);
effects.exit(types.chunkText)
return effects.attempt(markerConstruct, after, nok)
}

function after() {
effects.exit('spoiler');
return ok;
effects.exit('spoiler')
return ok
}

return start
Expand Down Expand Up @@ -102,35 +91,36 @@ function markerTokenize(effects, ok, nok) {
return start
}



function spoilerFromMarkdown() {
function enterHandler(token) {
this.enter({
type: 'spoiler',
children: []
}, token)
this.enter(
{
type: 'spoiler',
children: [],
},
token,
)
}

function exitHandler(token) {
const node = this.stack[this.stack.length - 1];
const node = this.stack[this.stack.length - 1]
this.exit(token)
node.data = {
...node.data,
hName: 'span',
hProperties: {
className: 'spoiler',
title: '你知道的太多了'
title: '你知道的太多了',
},
}
}

return {
enter: {
spoiler: enterHandler
spoiler: enterHandler,
},
exit: {
spoiler: exitHandler
}
spoiler: exitHandler,
},
}
}
Loading

0 comments on commit 9d0066e

Please sign in to comment.