Skip to content

Commit

Permalink
增加内建函数章节(待完成)
Browse files Browse the repository at this point in the history
nothing
  • Loading branch information
jinzhongjia committed Dec 16, 2023
1 parent 9690005 commit 7eda5d8
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 86 deletions.
4 changes: 4 additions & 0 deletions learn/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export default [
{
text: "更多",
items: [
{
text: "内建函数",
link: "/more/builtin_func",
},
{
text: "反射",
link: "/more/reflection",
Expand Down
78 changes: 41 additions & 37 deletions learn/.vitepress/theme/ImgViewer.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import Viewer from 'viewerjs';
import { nextTick, onMounted, watch } from 'vue';
import { Route } from 'vitepress';
import Viewer from "viewerjs";
import { nextTick, onMounted, watch } from "vue";
import { Route } from "vitepress";

/**
* 给图片添加预览功能
*/
const setViewer = (el: string = '.vp-doc img', option?: Viewer.Options) => {
// 默认配置
const defaultBaseOption: Viewer.Options = {
navbar: false,
title: false,
toolbar: {
zoomIn: 4,
zoomOut: 4,
prev: 4,
next: 4,
reset: 4,
oneToOne: 4
}
}
document.querySelectorAll(el).forEach((item: Element) => {
(item as HTMLElement).onclick = () => {
const viewer = new Viewer(<HTMLElement>item, {
...defaultBaseOption,
...option,
hide(e) {
viewer.destroy();
}
});
viewer.show()
}
(item as HTMLElement).style.cursor = "zoom-in";
});
const setViewer = (el: string = ".vp-doc img", option?: Viewer.Options) => {
// 默认配置
const defaultBaseOption: Viewer.Options = {
navbar: false,
title: false,
toolbar: {
zoomIn: 4,
zoomOut: 4,
prev: 4,
next: 4,
reset: 4,
oneToOne: 4,
},
};
document.querySelectorAll(el).forEach((item: Element) => {
(item as HTMLElement).onclick = () => {
const viewer = new Viewer(<HTMLElement>item, {
...defaultBaseOption,
...option,
hide(e) {
viewer.destroy();
},
});
viewer.show();
};
(item as HTMLElement).style.cursor = "zoom-in";
});
};

/**
Expand All @@ -44,12 +44,16 @@ const setViewer = (el: string = '.vp-doc img', option?: Viewer.Options) => {
* <br/>viewerjs 设置选项
*/
const imageViewer = (route: Route, el?: string, option?: Viewer.Options) => {
onMounted(() => {
onMounted(() => {
setViewer(el, option);
});
watch(
() => route.path,
() =>
nextTick(() => {
setViewer(el, option);
})
watch(() => route.path, () => nextTick(() => {
setViewer(el, option);
}));
}
}),
);
};

export default imageViewer;
export default imageViewer;
89 changes: 46 additions & 43 deletions learn/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
// .vitepress/theme/index.js
import DefaultTheme from 'vitepress/theme';
import DefaultTheme from "vitepress/theme";

import giscusTalk from 'vitepress-plugin-comment-with-giscus';
import giscusTalk from "vitepress-plugin-comment-with-giscus";

import codeblocksFold from 'vitepress-plugin-codeblocks-fold';
import 'vitepress-plugin-codeblocks-fold/style/index.scss';
import codeblocksFold from "vitepress-plugin-codeblocks-fold";
import "vitepress-plugin-codeblocks-fold/style/index.scss";

import 'viewerjs/dist/viewer.min.css';
import imageViewer from './ImgViewer';
import "viewerjs/dist/viewer.min.css";
import imageViewer from "./ImgViewer";

import { useData, useRoute } from 'vitepress';
import { useData, useRoute } from "vitepress";

export default {
...DefaultTheme,
enhanceApp(ctx) {
DefaultTheme.enhanceApp(ctx);
},
setup() {
// Get frontmatter and route
const { frontmatter } = useData();
const route = useRoute();

// code fold support
codeblocksFold({ route, frontmatter }, true, 400);

// imageView
imageViewer(route);

// Obtain configuration from: https://giscus.app/
giscusTalk({
repo: 'learnzig/learnzig',
repoId: 'R_kgDOKRsb5Q',
category: 'Comments', // default: `General`
categoryId: 'DIC_kwDOKRsb5c4Cbx2i',
mapping: 'pathname', // default: `pathname`
inputPosition: 'top', // default: `top`
lang: 'zh-CN', // default: `zh-CN`
strict: "1",
reactionsEnabled: "1",
// theme:"dark",
lightTheme: "light",
darkTheme:"dark"
}, {
frontmatter, route
},
true
);
}
};
...DefaultTheme,
enhanceApp(ctx) {
DefaultTheme.enhanceApp(ctx);
},
setup() {
// Get frontmatter and route
const { frontmatter } = useData();
const route = useRoute();

// code fold support
codeblocksFold({ route, frontmatter }, true, 400);

// imageView
imageViewer(route);

// Obtain configuration from: https://giscus.app/
giscusTalk(
{
repo: "learnzig/learnzig",
repoId: "R_kgDOKRsb5Q",
category: "Comments", // default: `General`
categoryId: "DIC_kwDOKRsb5c4Cbx2i",
mapping: "pathname", // default: `pathname`
inputPosition: "top", // default: `top`
lang: "zh-CN", // default: `zh-CN`
strict: "1",
reactionsEnabled: "1",
// theme:"dark",
lightTheme: "light",
darkTheme: "dark",
},
{
frontmatter,
route,
},
true,
);
},
};
7 changes: 7 additions & 0 deletions learn/more/builtin_func.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
outline: deep
---

# 内建函数

TODO
12 changes: 6 additions & 6 deletions learn/more/style_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ outline: deep

简单来说,使用 **驼峰命名法****TitleCase 命名法****蛇形命名法**

- 类型声明使用 *TitleCase 命名法*(除非是一个 0 字段的 `struct`,此时它被视为一个命名空间,应使用 *蛇形命名法*
- 如果 `x` 是可以被调用的,并且它返回一个类型,那么使用 *TitleCase 命名法*
- 如果 `x` 是可被调用,并且返回非类型,应使用 *驼峰命名法*
- 其他情况下,应该使用 *蛇形命名法*
- 类型声明使用 _TitleCase 命名法_(除非是一个 0 字段的 `struct`,此时它被视为一个命名空间,应使用 _蛇形命名法_
- 如果 `x` 是可以被调用的,并且它返回一个类型,那么使用 _TitleCase 命名法_
- 如果 `x` 是可被调用,并且返回非类型,应使用 _驼峰命名法_
- 其他情况下,应该使用 _蛇形命名法_

> 首字母缩略词、首字母缩写词、专有名词或任何其他在书面英语中具有大写规则的单词与任何其他单词一样,都受命名约定的约束。即使是只有 2 个字母的首字母缩略词也受这些约定的约束。
文件名分为两类:类型和命名空间,如果文件具有字段,则它应该使用 *TitleCase 命名法*,否则应使用 *蛇形命名法*,目录名称也应使用 *蛇形命名法*
文件名分为两类:类型和命名空间,如果文件具有字段,则它应该使用 _TitleCase 命名法_,否则应使用 _蛇形命名法_,目录名称也应使用 _蛇形命名法_

以上的约束是在一般情况下,如果已经有了内部约定,请使用内部约定!

Expand Down Expand Up @@ -101,4 +101,4 @@ fn readU32Be() u32 {}
- 根据名称省略冗余信息,即当可以立即从命名推断出其用途时,无需注释其用途
- 鼓励将注释信息复制到多个类似的函数上,这有助于 IDE 或者其他工具提供更好的帮助说明
- 对不变量使用 **假设** 来表示当违反事先预定情况时会发生未定义行为
- 使用 **断言** 表示当当违反预定情况时会触发安全检查的未定义行为
- 使用 **断言** 表示当当违反预定情况时会触发安全检查的未定义行为

0 comments on commit 7eda5d8

Please sign in to comment.