mirror of https://github.com/YunYouJun/valaxy
chore: lint to top-level function with function keyword
This commit is contained in:
parent
5b2f3a2d57
commit
2d7d0d6c1c
|
@ -428,7 +428,7 @@ To be able to handle i18n with CSS, we use markdown-it-container's fence to wrap
|
|||
:::
|
||||
|
||||
```ts
|
||||
export const containerPlugin = (md: MarkdownIt) => {
|
||||
export function containerPlugin(md: MarkdownIt) {
|
||||
// ...
|
||||
const languages = ['zh-CN', 'en']
|
||||
|
||||
|
@ -542,7 +542,7 @@ When switching languages, the following can be done.
|
|||
:::
|
||||
|
||||
```ts
|
||||
const toggleLocales = (lang: val) => {
|
||||
function toggleLocales(lang: val) {
|
||||
// ...
|
||||
// save locale
|
||||
localStorage.setItem('valaxy-locale', lang)
|
||||
|
|
|
@ -4,7 +4,7 @@ import { useSiteConfig } from 'valaxy'
|
|||
/**
|
||||
* init algolia watch
|
||||
*/
|
||||
export const useAddonAlgolia = () => {
|
||||
export function useAddonAlgolia() {
|
||||
const siteConfig = useSiteConfig()
|
||||
const isAlgolia = computed(() => siteConfig.value.search.type === 'algolia')
|
||||
const metaKey = ref('\'Meta\'')
|
||||
|
|
|
@ -16,7 +16,7 @@ const passSecond = ref(0)
|
|||
/**
|
||||
* get live time
|
||||
*/
|
||||
const siteLiveTime = () => {
|
||||
function siteLiveTime() {
|
||||
const start = new Date(props.startTime)
|
||||
const now = new Date()
|
||||
const timeDiff = (now.getTime() - start.getTime())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export const getEmojis = (cdn = '//unpkg.com/') => {
|
||||
export function getEmojis(cdn = '//unpkg.com/') {
|
||||
return [
|
||||
`${cdn}@waline/emojis/bilibili/`,
|
||||
`${cdn}@waline/emojis/qq/`,
|
||||
|
|
|
@ -21,7 +21,7 @@ const props = withDefaults(defineProps<{
|
|||
const collapsable = ref(props.collapsable)
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
const getTitle = (post: Post | any) => {
|
||||
function getTitle(post: Post | any) {
|
||||
const lang = locale.value
|
||||
return post[`title_${lang}`] ? post[`title_${lang}`] : post.title
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<script lang="ts" setup>
|
||||
import type { PageData, Post } from 'valaxy'
|
||||
import { usePostTitle, useSiteConfig } from 'valaxy'
|
||||
import { StyleValue, computed } from 'vue'
|
||||
import type { StyleValue } from 'vue'
|
||||
import { computed } from 'vue'
|
||||
import { usePostProperty } from '../composables'
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* @description https://github.com/YunYouJun/hexo-theme-yun
|
||||
*/
|
||||
|
||||
import { CSSProperties, computed, onBeforeMount, ref } from 'vue'
|
||||
import type { CSSProperties } from 'vue'
|
||||
import { computed, onBeforeMount, ref } from 'vue'
|
||||
import { random } from 'valaxy'
|
||||
import { useThemeConfig } from '../composables'
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ const { t } = useI18n()
|
|||
* i18n
|
||||
*/
|
||||
const { locale } = useI18n()
|
||||
const getTitle = (post: Post | any) => {
|
||||
function getTitle(post: Post | any) {
|
||||
const lang = locale.value === 'zh-CN' ? 'zh' : locale.value
|
||||
return post[`title_${lang}`] ? post[`title_${lang}`] : post.title
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ const { show } = useInvisibleElement(postCollapseElRef)
|
|||
* scroll to post collapse by category
|
||||
* @param category
|
||||
*/
|
||||
const jumpToDisplayCategory = (category: string) => {
|
||||
function jumpToDisplayCategory(category: string) {
|
||||
router.push({
|
||||
query: {
|
||||
category,
|
||||
|
|
|
@ -62,7 +62,7 @@ watch(() => props.open, async () => {
|
|||
})
|
||||
|
||||
const router = useRouter()
|
||||
const jumpToLink = (link: string) => {
|
||||
function jumpToLink(link: string) {
|
||||
router.push(link)
|
||||
emit('close')
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts" setup>
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { Post } from 'valaxy'
|
||||
import { StyleValue } from 'vue'
|
||||
import type { StyleValue } from 'vue'
|
||||
import { usePostProperty } from '../composables'
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
|
@ -10,7 +10,7 @@ const isFuse = computed(() => siteConfig.value.search.type === 'fuse')
|
|||
|
||||
const open = ref(false)
|
||||
|
||||
const togglePopup = () => {
|
||||
function togglePopup() {
|
||||
open.value = !open.value
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ const posts = computed(() => {
|
|||
const collapse = ref()
|
||||
const { show } = useInvisibleElement(collapse)
|
||||
|
||||
const displayTag = (tag: string) => {
|
||||
function displayTag(tag: string) {
|
||||
router.push({
|
||||
query: {
|
||||
tag,
|
||||
|
|
|
@ -4,7 +4,7 @@ export const anonymousImage = 'https://cdn.yunyoujun.cn/img/avatar/none.jpg'
|
|||
* set default img
|
||||
* @param e
|
||||
*/
|
||||
export const onImgError = (e: Event, defaultImg = anonymousImage) => {
|
||||
export function onImgError(e: Event, defaultImg = anonymousImage) {
|
||||
const targetEl = e.target as HTMLImageElement
|
||||
targetEl.setAttribute('data-src', targetEl.src)
|
||||
targetEl.src = defaultImg
|
||||
|
|
|
@ -29,7 +29,7 @@ const surLen = computed(() => {
|
|||
return 2
|
||||
})
|
||||
|
||||
const showPage = (i: number) => {
|
||||
function showPage(i: number) {
|
||||
if (i === 1)
|
||||
return true
|
||||
else if (i === totalPages.value)
|
||||
|
@ -37,7 +37,7 @@ const showPage = (i: number) => {
|
|||
return i > props.curPage - surLen.value && i < props.curPage + surLen.value
|
||||
}
|
||||
|
||||
const jumpTo = (page: number) => {
|
||||
function jumpTo(page: number) {
|
||||
emit('pageChange', page)
|
||||
if (page === 1)
|
||||
return '/'
|
||||
|
|
|
@ -22,7 +22,9 @@ export type Category = CategoryList
|
|||
export type Categories = (Post | CategoryList)[]
|
||||
|
||||
// todo write unit test
|
||||
export const isCategoryList = (category: any): category is CategoryList => category.children
|
||||
export function isCategoryList(category: any): category is CategoryList {
|
||||
return category.children
|
||||
}
|
||||
|
||||
/**
|
||||
* get categories from posts
|
||||
|
|
|
@ -5,7 +5,7 @@ import { onMounted } from 'vue'
|
|||
/**
|
||||
* @description image preview by medium-zoom
|
||||
*/
|
||||
export const useMediumZoom = () => {
|
||||
export function useMediumZoom() {
|
||||
const siteConfig = useSiteConfig()
|
||||
const mediumZoomConfig = siteConfig.value.mediumZoom
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { useI18n } from 'vue-i18n'
|
|||
import dayjs from 'dayjs'
|
||||
import 'dayjs/locale/zh-cn'
|
||||
|
||||
export const useLocale = () => {
|
||||
export function useLocale() {
|
||||
const { availableLocales, locale } = useI18n()
|
||||
const lang = useStorage('valaxy-locale', locale.value)
|
||||
dayjs.locale(lang.value.toLowerCase())
|
||||
|
|
|
@ -66,7 +66,7 @@ function addToParent(
|
|||
* export headers & handleClick to generate outline
|
||||
* @returns
|
||||
*/
|
||||
export const useOutline = () => {
|
||||
export function useOutline() {
|
||||
const frontmatter = useFrontmatter()
|
||||
const themeConfig = useThemeConfig()
|
||||
const headers = ref<MenuItem[]>([])
|
||||
|
|
|
@ -6,7 +6,7 @@ import type { Post } from 'valaxy'
|
|||
import { sortByDate } from '../utils'
|
||||
import { useSiteStore } from '../stores'
|
||||
|
||||
export const usePostTitle = (post: ComputedRef<Post>) => {
|
||||
export function usePostTitle(post: ComputedRef<Post>) {
|
||||
const { locale } = useI18n()
|
||||
return computed(() => {
|
||||
const lang = locale.value === 'zh-CN' ? 'zh' : locale.value
|
||||
|
|
|
@ -5,7 +5,7 @@ import { useI18n } from 'vue-i18n'
|
|||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
|
||||
const back = () => {
|
||||
function back() {
|
||||
if (document.referrer)
|
||||
router.back()
|
||||
else
|
||||
|
|
|
@ -13,7 +13,7 @@ export function wrap(el: HTMLElement, className: string) {
|
|||
/**
|
||||
* 包裹表格,添加 class 以控制 table 样式
|
||||
*/
|
||||
export const wrapTable = (container: HTMLElement | Document = document) => {
|
||||
export function wrapTable(container: HTMLElement | Document = document) {
|
||||
container.querySelectorAll('table').forEach((el) => {
|
||||
const container = document.createElement('div')
|
||||
container.className = 'table-container'
|
||||
|
|
|
@ -69,7 +69,7 @@ export async function ssgBuild(
|
|||
* todo find why
|
||||
* @param options
|
||||
*/
|
||||
export const postProcessForSSG = async (options: ResolvedValaxyOptions) => {
|
||||
export async function postProcessForSSG(options: ResolvedValaxyOptions) {
|
||||
const { userRoot } = options
|
||||
const indexPath = resolve(userRoot, 'dist/index.html')
|
||||
if (fs.existsSync(indexPath)) {
|
||||
|
|
|
@ -54,7 +54,7 @@ export async function generateFuseList(options: ResolvedValaxyOptions) {
|
|||
* valaxy fuse
|
||||
* @param cli
|
||||
*/
|
||||
export const registerFuseCommand = (cli: Argv<{}>) => {
|
||||
export function registerFuseCommand(cli: Argv<{}>) {
|
||||
cli.command(
|
||||
'fuse [root]',
|
||||
'generate fuse list for search',
|
||||
|
|
|
@ -7,7 +7,7 @@ import { type CreatePostParams, create } from './utils/post'
|
|||
* register new post command
|
||||
* @param cli
|
||||
*/
|
||||
export const registerNewCommand = (cli: Argv<{}>) => {
|
||||
export function registerNewCommand(cli: Argv<{}>) {
|
||||
cli.command(
|
||||
'new <title>',
|
||||
'Draft a new post',
|
||||
|
|
|
@ -16,7 +16,7 @@ export interface CreatePostParams {
|
|||
|
||||
const pagesPath = resolve(userRoot, 'pages')
|
||||
|
||||
export const create = async (data: CreatePostParams) => {
|
||||
export async function create(data: CreatePostParams) {
|
||||
const {
|
||||
path,
|
||||
title,
|
||||
|
|
|
@ -4,7 +4,7 @@ import { resolveOptions } from '../../options'
|
|||
import { exists } from './fs'
|
||||
import { userRoot } from './constants'
|
||||
|
||||
export const getTemplate = async (layout: string): Promise<string | false> => {
|
||||
export async function getTemplate(layout: string): Promise<string | false> {
|
||||
const { clientRoot, themeRoot } = await resolveOptions({ userRoot })
|
||||
const roots = [userRoot, themeRoot, clientRoot]
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)
|
|||
* 2. convert line numbers into line options:
|
||||
* [{ line: number, classes: string[] }]
|
||||
*/
|
||||
const attrsToLines = (attrs: string): HtmlRendererOptions['lineOptions'] => {
|
||||
function attrsToLines(attrs: string): HtmlRendererOptions['lineOptions'] {
|
||||
attrs = attrs.replace(/^(?:\[.*?\])?.*?([\d,-]+).*/, '$1').trim()
|
||||
const result: number[] = []
|
||||
if (!attrs)
|
||||
|
|
|
@ -148,9 +148,7 @@ export async function setupMarkdownPlugins(
|
|||
return md as MarkdownRenderer
|
||||
}
|
||||
|
||||
export const createMarkdownRenderer = async (
|
||||
mdOptions: MarkdownOptions = {},
|
||||
): Promise<MarkdownRenderer> => {
|
||||
export async function createMarkdownRenderer(mdOptions: MarkdownOptions = {}): Promise<MarkdownRenderer> {
|
||||
const md = MarkdownIt({
|
||||
html: true,
|
||||
linkify: true,
|
||||
|
|
|
@ -100,7 +100,7 @@ const defaultBlocksOptions: Blocks = {
|
|||
},
|
||||
}
|
||||
|
||||
export const containerPlugin = (md: MarkdownIt, options: Blocks = {}) => {
|
||||
export function containerPlugin(md: MarkdownIt, options: Blocks = {}) {
|
||||
Object.keys(defaultBlocksOptions).forEach((optionKey) => {
|
||||
const option: BlockItem = {
|
||||
...defaultBlocksOptions[optionKey as keyof Blocks],
|
||||
|
|
|
@ -3,7 +3,7 @@ import type MarkdownIt from 'markdown-it'
|
|||
|
||||
const wrapperRE = /^<pre .*?><code>/
|
||||
|
||||
export const highlightLinePlugin = (md: MarkdownIt) => {
|
||||
export function highlightLinePlugin(md: MarkdownIt) {
|
||||
const fence = md.renderer.rules.fence!
|
||||
md.renderer.rules.fence = (...args) => {
|
||||
const [tokens, idx, options] = args
|
||||
|
@ -59,7 +59,7 @@ export const highlightLinePlugin = (md: MarkdownIt) => {
|
|||
// 2. <!--afterbegin-->
|
||||
// 3. <!--beforeend-->
|
||||
// 4. <!--afterend-->
|
||||
export const preWrapperPlugin = (md: MarkdownIt) => {
|
||||
export function preWrapperPlugin(md: MarkdownIt) {
|
||||
const fence = md.renderer.rules.fence!
|
||||
md.renderer.rules.fence = (...args) => {
|
||||
const [tokens, idx] = args
|
||||
|
@ -71,7 +71,7 @@ export const preWrapperPlugin = (md: MarkdownIt) => {
|
|||
|
||||
// markdown-it plugin for generating line numbers.
|
||||
// It depends on preWrapper plugin.
|
||||
export const lineNumberPlugin = (md: MarkdownIt) => {
|
||||
export function lineNumberPlugin(md: MarkdownIt) {
|
||||
const fence = md.renderer.rules.fence!
|
||||
md.renderer.rules.fence = (...args) => {
|
||||
const rawCode = fence(...args)
|
||||
|
|
|
@ -57,11 +57,9 @@ export interface MarkdownCompileResult {
|
|||
includes: string[]
|
||||
}
|
||||
|
||||
const inferTitle = (
|
||||
md: MarkdownRenderer,
|
||||
function inferTitle(md: MarkdownRenderer,
|
||||
frontmatter: Record<string, any>,
|
||||
title: string,
|
||||
) => {
|
||||
title: string) {
|
||||
if (typeof frontmatter.title === 'string') {
|
||||
const titleToken = md.parseInline(frontmatter.title, {})[0]
|
||||
if (titleToken) {
|
||||
|
@ -74,10 +72,8 @@ const inferTitle = (
|
|||
return title
|
||||
}
|
||||
|
||||
const getHeadMetaContent = (
|
||||
head: HeadConfig[],
|
||||
name: string,
|
||||
): string | undefined => {
|
||||
function getHeadMetaContent(head: HeadConfig[],
|
||||
name: string): string | undefined {
|
||||
if (!head || !head.length)
|
||||
return undefined
|
||||
|
||||
|
@ -88,7 +84,7 @@ const getHeadMetaContent = (
|
|||
return meta && meta[1].content
|
||||
}
|
||||
|
||||
const inferDescription = (frontmatter: Record<string, any>) => {
|
||||
function inferDescription(frontmatter: Record<string, any>) {
|
||||
const { description, head } = frontmatter
|
||||
|
||||
if (description !== undefined)
|
||||
|
|
|
@ -11,11 +11,9 @@ import type { MarkdownEnv } from '../env'
|
|||
|
||||
const indexRE = /(^|.*\/)index.md(#?.*)$/i
|
||||
|
||||
export const linkPlugin = (
|
||||
md: MarkdownIt,
|
||||
export function linkPlugin(md: MarkdownIt,
|
||||
externalAttrs: Record<string, string>,
|
||||
base: string,
|
||||
) => {
|
||||
base: string) {
|
||||
md.renderer.rules.link_open = (
|
||||
tokens,
|
||||
idx,
|
||||
|
|
|
@ -5,7 +5,7 @@ const rControl = /[\u0000-\u001F]/g
|
|||
// add '…'
|
||||
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.…?/]+/g
|
||||
|
||||
export const slugify = (str: string): string => {
|
||||
export function slugify(str: string): string {
|
||||
return (
|
||||
removeDiacritics(str)
|
||||
// Remove control characters
|
||||
|
|
|
@ -33,7 +33,7 @@ const mdIt = new MarkdownIt({ html: true })
|
|||
* @param type
|
||||
* @returns
|
||||
*/
|
||||
const getExcerptByType = (excerpt = '', type: 'md' | 'html' | 'text' = 'html') => {
|
||||
function getExcerptByType(excerpt = '', type: 'md' | 'html' | 'text' = 'html') {
|
||||
switch (type) {
|
||||
case 'md':
|
||||
return excerpt
|
||||
|
|
|
@ -8,7 +8,7 @@ export type ReadTimeOptions = SiteConfig['statistics']['readTime']
|
|||
/**
|
||||
* count characters
|
||||
*/
|
||||
export const count = (content: string): CountData => {
|
||||
export function count(content: string): CountData {
|
||||
const cn = (content.match(/[\u4E00-\u9FA5]/g) || []).length
|
||||
const en = (content.replace(/[\u4E00-\u9FA5]/g, '').match(/[a-zA-Z0-9_\u0392-\u03C9\u0400-\u04FF]+|[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF\u3040-\u309F\uAC00-\uD7AF\u0400-\u04FF]+|[\u00E4\u00C4\u00E5\u00C5\u00F6\u00D6]+|\w+/g) || []).length
|
||||
return {
|
||||
|
@ -23,9 +23,8 @@ export const count = (content: string): CountData => {
|
|||
* @param param1
|
||||
* @returns read time (minute)
|
||||
*/
|
||||
export const readTime = (
|
||||
{ cn, en }: CountData,
|
||||
options: ReadTimeOptions) => {
|
||||
export function readTime({ cn, en }: CountData,
|
||||
options: ReadTimeOptions) {
|
||||
const readingTime = cn / (options.speed.cn || 300) + en / (options.speed.en || 100)
|
||||
return readingTime < 1 ? 1 : Math.ceil(readingTime)
|
||||
}
|
||||
|
@ -35,7 +34,7 @@ export const readTime = (
|
|||
* @param content
|
||||
* @returns
|
||||
*/
|
||||
export const wordCount = ({ cn, en }: CountData) => {
|
||||
export function wordCount({ cn, en }: CountData) {
|
||||
const num = cn + en
|
||||
if (num < 1000)
|
||||
return num
|
||||
|
@ -43,9 +42,9 @@ export const wordCount = ({ cn, en }: CountData) => {
|
|||
return `${Math.round(num / 100) / 10}k`
|
||||
}
|
||||
|
||||
export const statistics = (content: string, options: {
|
||||
export function statistics(content: string, options: {
|
||||
readTime: ReadTimeOptions
|
||||
}) => {
|
||||
}) {
|
||||
const countData = count(content)
|
||||
return {
|
||||
countData,
|
||||
|
@ -55,13 +54,13 @@ export const statistics = (content: string, options: {
|
|||
}
|
||||
|
||||
// preset addon for statistics
|
||||
export const presetStatistics = ({
|
||||
export function presetStatistics({
|
||||
route,
|
||||
options,
|
||||
}: {
|
||||
route: Parameters<Required<ValaxyExtendConfig>['extendMd']>[0]['route']
|
||||
options: SiteConfig['statistics']
|
||||
}) => {
|
||||
}) {
|
||||
if (existsSync(route.component)) {
|
||||
const file = readFileSync(route.component, 'utf-8')
|
||||
const { wordCount, readingTime } = statistics(file, {
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
import type { ResolvedValaxyOptions } from '../options'
|
||||
import { loadSetups } from './setupNode'
|
||||
|
||||
export const createSafelist = async (options: ResolvedValaxyOptions) => {
|
||||
export async function createSafelist(options: ResolvedValaxyOptions) {
|
||||
const { config } = options
|
||||
const safeIcons: string[] = [
|
||||
'i-ri-clipboard-line',
|
||||
|
@ -45,7 +45,7 @@ export const createSafelist = async (options: ResolvedValaxyOptions) => {
|
|||
return safelist
|
||||
}
|
||||
|
||||
export const createUnocssConfig = async (options: ResolvedValaxyOptions) => {
|
||||
export async function createUnocssConfig(options: ResolvedValaxyOptions) {
|
||||
const { config: pluginOptions } = options
|
||||
|
||||
const unocssConfig: VitePluginConfig = {
|
||||
|
@ -97,7 +97,7 @@ export const createUnocssConfig = async (options: ResolvedValaxyOptions) => {
|
|||
return unocssConfig
|
||||
}
|
||||
|
||||
export const createUnocssPlugin = async (options: ResolvedValaxyOptions) => {
|
||||
export async function createUnocssPlugin(options: ResolvedValaxyOptions) {
|
||||
const UnoCSS = await import('unocss/vite').then(r => r.default)
|
||||
const { unocss: unoOptions } = options.config
|
||||
const defaultConfig = await createUnocssConfig(options)
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import { logger } from '../logger'
|
||||
|
||||
export const isProd = () => process.env.NODE_ENV === 'production'
|
||||
export function isProd() {
|
||||
return process.env.NODE_ENV === 'production'
|
||||
}
|
||||
|
||||
export const setEnv = (env = 'development') => {
|
||||
export function setEnv(env = 'development') {
|
||||
process.env.NODE_ENV = env
|
||||
logger.level = isProd() ? 2 : 3
|
||||
}
|
||||
|
||||
export const setEnvProd = () => setEnv('production')
|
||||
export function setEnvProd() {
|
||||
return setEnv('production')
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export * from './config'
|
|||
* @param obj
|
||||
* @returns
|
||||
*/
|
||||
export const transformObject = (obj: any) => {
|
||||
export function transformObject(obj: any) {
|
||||
return `JSON.parse(${JSON.stringify(JSON.stringify(obj))})`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue