diff --git a/README.md b/README.md index ede5995ca2f..a7470fd423d 100644 --- a/README.md +++ b/README.md @@ -19,146 +19,147 @@ Quick Reference 坑已挖,需要您的参与完善和贡献!🙏 -[Ansible](./docs/ansible.md) -[CMake](./docs/cmake.md) -[C#](./docs/cs.md) -[Django](./docs/djiango.md) -[FFmpeg](./docs/ffmpeg.md) -[Flutter](./docs/flutter.md) -[LaTeX](./docs/latex.md) -[Lua](./docs/lua.md) -[MATLAB](./docs/matlab.md) -[Vue 3](./docs/vue.md) -[Pytorch](./docs/pytorch.md) +[Ansible](./docs/ansible.md) +[CMake](./docs/cmake.md) +[C#](./docs/cs.md) +[Django](./docs/djiango.md) +[FFmpeg](./docs/ffmpeg.md) +[Flutter](./docs/flutter.md) +[LaTeX](./docs/latex.md) +[Lua](./docs/lua.md) +[NestJS](./docs/nestjs.md) +[MATLAB](./docs/matlab.md) +[Vue 3](./docs/vue.md) +[Pytorch](./docs/pytorch.md) ## 编程 -[Bash](./docs/bash.md) -[C](./docs/c.md) -[C#](./docs/cs.md) -[CPP](./docs/cpp.md) -[Dart](./docs/dart.md) -[Docker](./docs/docker.md) -[Dockerfile](./docs/dockerfile.md) -[Django](./docs/djiango.md) -[Flutter](./docs/flutter.md) -[Golang](./docs/golang.md) -[GraphQL](./docs/graphql.md) -[INI](./docs/ini.md) -[JSON](./docs/json.md) -[Java](./docs/java.md) -[Julia](./docs/julia.md) -[Kotlin](./docs/kotlin.md) -[LaTeX](./docs/latex.md) -[Markdown](./docs/markdown.md) -[MySQL](./docs/mysql.md) -[MATLAB](./docs/matlab.md) -[PHP](./docs/php.md) -[Python](./docs/python.md) -[PostgreSQL](./docs/postgres.md) -[Ruby](./docs/ruby.md) -[Rust](./docs/rust.md) -[Swift](./docs/swift.md) -[SwiftUI](./docs/swiftui.md) -[TOML](./docs/toml.md) -[YAML](./docs/yaml.md) -[Lua](./docs/lua.md) -[Pytorch](./docs/pytorch.md) +[Bash](./docs/bash.md) +[C](./docs/c.md) +[C#](./docs/cs.md) +[CPP](./docs/cpp.md) +[Dart](./docs/dart.md) +[Docker](./docs/docker.md) +[Dockerfile](./docs/dockerfile.md) +[Django](./docs/djiango.md) +[Flutter](./docs/flutter.md) +[Golang](./docs/golang.md) +[GraphQL](./docs/graphql.md) +[INI](./docs/ini.md) +[JSON](./docs/json.md) +[Java](./docs/java.md) +[Julia](./docs/julia.md) +[Kotlin](./docs/kotlin.md) +[LaTeX](./docs/latex.md) +[Markdown](./docs/markdown.md) +[MySQL](./docs/mysql.md) +[MATLAB](./docs/matlab.md) +[PHP](./docs/php.md) +[Python](./docs/python.md) +[PostgreSQL](./docs/postgres.md) +[Ruby](./docs/ruby.md) +[Rust](./docs/rust.md) +[Swift](./docs/swift.md) +[SwiftUI](./docs/swiftui.md) +[TOML](./docs/toml.md) +[YAML](./docs/yaml.md) +[Lua](./docs/lua.md) +[Pytorch](./docs/pytorch.md) ## 前端 -[CSS 3](./docs/css.md) -[Electron](./docs/electron.md) -[Emmet](./docs/emmet.md) -[ES 6](./docs/es6.md) -[Styled Components](./docs/styled-components.md) -[Stylus](./docs/stylus.md) -[Sass](./docs/sass.md) -[HTML](./docs/html.md) -[JavaScript](./docs/javascript.md) -[Less.js](./docs/lessjs.md) -[React](./docs/react.md) -[RegEx 正则表达式](./docs/regex.md) -[TypeScript](./docs/typescript.md) -[Vue 2](./docs/vue2.md) -[Vue 3](./docs/vue.md) +[CSS 3](./docs/css.md) +[Electron](./docs/electron.md) +[Emmet](./docs/emmet.md) +[ES 6](./docs/es6.md) +[Styled Components](./docs/styled-components.md) +[Stylus](./docs/stylus.md) +[Sass](./docs/sass.md) +[HTML](./docs/html.md) +[JavaScript](./docs/javascript.md) +[Less.js](./docs/lessjs.md) +[React](./docs/react.md) +[RegEx 正则表达式](./docs/regex.md) +[TypeScript](./docs/typescript.md) +[Vue 2](./docs/vue2.md) +[Vue 3](./docs/vue.md) ## Nodejs -[Express.js](./docs/expressjs.md) -[Jest](./docs/jest.md) -[Koa.js](./docs/koajs.md) -[Lerna](./docs/lerna.md) -[npm](./docs/npm.md) -[package.json](./docs/package.json.md) -[Yarn](./docs/yarn.md) -[NestJS](./docs/nestjs.md) +[Express.js](./docs/expressjs.md) +[Jest](./docs/jest.md) +[Koa.js](./docs/koajs.md) +[Lerna](./docs/lerna.md) +[npm](./docs/npm.md) +[NestJS](./docs/nestjs.md) +[package.json](./docs/package.json.md) +[Yarn](./docs/yarn.md) ## 工具 -[Emacs](./docs/emacs.md) -[Gmail](./docs/gmail.md) -[nginx](./docs/nginx.md) -[Semver](./docs/semver.md) -[Sketch](./docs/sketch.md) -[Sublime Text](./docs/sublime-text.md) -[VSCode](./docs/vscode.md) -[Vim](./docs/vim.md) -[WebStorm](./docs/webstorm.md) -[XPath](./docs/xpath.md) -[Xcode](./docs/xcode.md) +[Emacs](./docs/emacs.md) +[Gmail](./docs/gmail.md) +[nginx](./docs/nginx.md) +[Semver](./docs/semver.md) +[Sketch](./docs/sketch.md) +[Sublime Text](./docs/sublime-text.md) +[VSCode](./docs/vscode.md) +[Vim](./docs/vim.md) +[WebStorm](./docs/webstorm.md) +[XPath](./docs/xpath.md) +[Xcode](./docs/xcode.md) ## 命令 -[Ansible](./docs/ansible.md) -[Awk](./docs/awk.md) -[Conan](./docs/conan.md) -[CocoaPods](./docs/cocoapods.md) -[Cargo](./docs/cargo.md) -[Curl](./docs/curl.md) -[Chmod](./docs/chmod.md) -[Cron](./docs/cron.md) -[CMake](./docs/cmake.md) -[Git](./docs/git.md) -[Grep](./docs/grep.md) -[Find](./docs/find.md) -[FFmpeg](./docs/ffmpeg.md) -[Htop](./docs/htop.md) -[Homebrew](./docs/homebrew.md) -[Netstat](./docs/netstat.md) -[jq](./docs/jq.md) -[Lsof](./docs/lsof.md) -[Mitmproxy](./docs/mitmproxy.md) -[Netcat](./docs/netcat.md) -[Sed](./docs/sed.md) -[OpenSSL](./docs/openssl.md) -[Systemd](./docs/systemd.md) -[SSH](./docs/ssh.md) -[Screen](./docs/screen.md) -[Sysdig](./docs/sysdig.md) -[Tmux](./docs/tmux.md) -[YUM](./docs/yum.md) -[CMD](./docs/cmd.md) -[APT](./docs/apt.md) -[tar](./docs/tar.md) +[Ansible](./docs/ansible.md) +[Awk](./docs/awk.md) +[Conan](./docs/conan.md) +[CocoaPods](./docs/cocoapods.md) +[Cargo](./docs/cargo.md) +[Curl](./docs/curl.md) +[Chmod](./docs/chmod.md) +[Cron](./docs/cron.md) +[CMake](./docs/cmake.md) +[Git](./docs/git.md) +[Grep](./docs/grep.md) +[Find](./docs/find.md) +[FFmpeg](./docs/ffmpeg.md) +[Htop](./docs/htop.md) +[Homebrew](./docs/homebrew.md) +[Netstat](./docs/netstat.md) +[jq](./docs/jq.md) +[Lsof](./docs/lsof.md) +[Mitmproxy](./docs/mitmproxy.md) +[Netcat](./docs/netcat.md) +[Sed](./docs/sed.md) +[OpenSSL](./docs/openssl.md) +[Systemd](./docs/systemd.md) +[SSH](./docs/ssh.md) +[Screen](./docs/screen.md) +[Sysdig](./docs/sysdig.md) +[Tmux](./docs/tmux.md) +[YUM](./docs/yum.md) +[CMD](./docs/cmd.md) +[APT](./docs/apt.md) +[tar](./docs/tar.md) ## 其它 -[Quick Reference](./docs/quickreference.md) -[Github Actions](./docs/github-actions.md) -[Colors Named](./docs/colors-named.md) -[HTTP 状态码](./docs/http-status-code.md) -[HTML 字符实体](./docs/html-char.md) -[ISO 639-1 Language Code](./docs/iso-639-1.md) -[Emoji](./docs/emoji.md) -[MIME types](./docs/mime.md) -[Resolutions](./docs/resolutions.md) +[Quick Reference](./docs/quickreference.md) +[Github Actions](./docs/github-actions.md) +[Colors Named](./docs/colors-named.md) +[HTTP 状态码](./docs/http-status-code.md) +[HTML 字符实体](./docs/html-char.md) +[ISO 639-1 Language Code](./docs/iso-639-1.md) +[Emoji](./docs/emoji.md) +[MIME types](./docs/mime.md) +[Resolutions](./docs/resolutions.md) ## 看到缺少什么了吗? @@ -314,8 +315,8 @@ Quick Reference 由于中国国内访问,时常打不开,你可以访问下面镜像网站。推荐我的[镜像网站](https://github.com/jaywcjlove/reference/issues/102#issue-1451649637) -[ecdata.cn](http://ref.ecdata.cn/) -[mofe.io](http://quickref.mofe.io) +[ecdata.cn](http://ref.ecdata.cn/) +[mofe.io](http://quickref.mofe.io) 如果你有资源,可以很方便部署 web 版,这非常简单,只需要克隆 gh-pages 分支代码到你的静态服务就可以了,还可以使用 [docker](https://hub.docker.com/r/wcjiang/reference) 快捷部署 web 版。 diff --git a/scripts/create.mjs b/scripts/create.mjs index 8e53177a958..39f07d853a1 100644 --- a/scripts/create.mjs +++ b/scripts/create.mjs @@ -82,7 +82,14 @@ export function create(str = '', options = {}) { if (iconName) { detailData.icon = iconName; } - homeCardIcons(node, parent, options.isHome); + const resultHomeCard = homeCardIcons(node, parent, options.isHome); + if (options.filename && resultHomeCard[options.filename]) { + detailData.rgb = resultHomeCard[options.filename].rgb; + detailData.name = resultHomeCard[options.filename].title; + if (resultHomeCard[options.filename].tags) { + detailData.tags = resultHomeCard[options.filename].tags; + } + } tooltips(node, index, parent); htmlTagAddAttri(node, options); rehypeUrls(node); @@ -111,7 +118,6 @@ export function create(str = '', options = {}) { } node.children.unshift(header(options)); node.children.push(footer(options)); - // node.children.push(search(options)); node.children = node.children.concat(search(options)); } } diff --git a/scripts/js/main.js b/scripts/js/main.js index 8700ff88f0d..72189076e10 100644 --- a/scripts/js/main.js +++ b/scripts/js/main.js @@ -41,8 +41,9 @@ const fuse = new Fuse(REFS_DATA, { matchEmptyQuery: !0, threshold: .1, keys: [ - { name: "title", weight: 12 }, + { name: "name", weight: 12 }, { name: 'intro', weight: 2 }, + { name: 'tags', weight: 2 }, { name: 'sections.t', weight: 5 } ], }); @@ -70,9 +71,13 @@ document.addEventListener('keydown', (ev) => { } }); +let result = [] +let inputValue = ''; + function showSearch() { document.body.classList.add('search'); searchBox.classList.add('show'); + searchResult('') searchInput.focus(); } @@ -80,22 +85,29 @@ function hideSearch() { document.body.classList.remove('search'); searchBox.classList.remove('show'); } -let result = [] -let inputValue = ''; +function getValueReg(val = '') { + return new RegExp(val.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'), 'ig'); +} function searchResult(value) { inputValue = value; result = fuse.search(value); + if (!value) { + result = REFS_DATA.map(item => ({ item: item })); + } let menuHTML = ''; result.forEach((item, idx) => { - const label = item.item.title.replace(new RegExp(value, 'ig'), (txt) => { + const label = item.item.name.replace(getValueReg(value), (txt) => { + return `${txt}` + }) + const tags = (item.item.tags || []).join(',').replace(getValueReg(value), (txt) => { return `${txt}` }) const href = isHome ? item.item.path : item.item.path.replace('docs/', ''); if (idx === 0) { - menuHTML += `${label}`; + menuHTML += `${label}${tags}`; } else { - menuHTML += `${label}`; + menuHTML += `${label}${tags}`; } }); searchMenu.innerHTML = menuHTML; @@ -116,13 +128,13 @@ function searchResult(value) { function searchSectionsResult(idx = 0) { const data = result[idx] || []; - const title = (data.item?.intro || '').replace(new RegExp(inputValue, 'ig'), (txt) => { + const title = (data.item?.intro || '').replace(getValueReg(inputValue), (txt) => { return `${txt}` }); let sectionHTML = `

${title}

    `; if (data && data.item && data.item.sections) { data.item.sections.forEach((item, idx) => { - const label = item.t.replace(new RegExp(inputValue, 'ig'), (txt) => { + const label = item.t.replace(getValueReg(inputValue), (txt) => { return `${txt}` }) const href = isHome ? data.item.path : data.item.path.replace('docs/', ''); diff --git a/scripts/style/style.css b/scripts/style/style.css index be8dc044f2b..57c1a50dbe0 100644 --- a/scripts/style/style.css +++ b/scripts/style/style.css @@ -1234,7 +1234,6 @@ body.search { height: 100%; } #mysearch.show .mysearch-result > * { - width: 50%; overflow-y: auto; padding: 0.6rem; } @@ -1319,12 +1318,24 @@ body.search { white-space: pre-wrap; text-decoration: none; color: var(--color-fg-default); + align-items: center; + justify-content: space-between; +} +#mysearch-menu a > sup { + color: var(--color-fg-subtle); + font-size: 0.7rem; } #mysearch-menu a:hover, #mysearch-menu a.active { background-color: var(--color-neutral-muted); border-radius: 0.5rem; } +#mysearch-menu { + width: 25rem; +} +#mysearch-content { + flex: 1; +} #mysearch-content ol li div a:hover { background-color: var(--primary-color); color: #fff; diff --git a/scripts/utils/homeCardIcons.mjs b/scripts/utils/homeCardIcons.mjs index bc8d221b260..067d5f11083 100644 --- a/scripts/utils/homeCardIcons.mjs +++ b/scripts/utils/homeCardIcons.mjs @@ -1,7 +1,11 @@ import fs from 'fs-extra'; import path from 'path'; +import { getCodeString } from 'rehype-rewrite'; import { getSVGNode, ICONS_PATH } from './getSVGNode.mjs'; +const resultHomeCard = {}; +const COLOR_REG = /background:(\s+)?rgb\(([\d]+\s+[\d]+\s+[\d]+(\s+)?)\);?/gi; + export function homeCardIcons(node, parent, isHome) { if ( isHome && @@ -22,16 +26,23 @@ export function homeCardIcons(node, parent, isHome) { ) { node.children = node.children.map((child) => { const href = child.properties?.href; - if (href) { + if (href && href.endsWith('.md')) { const iconName = path.basename(href, '.md'); const iconPath = path.resolve(ICONS_PATH, `${iconName}.svg`); const iconDefaultPath = path.resolve(ICONS_PATH, `list.svg`); const iconExist = fs.existsSync(iconPath); + let color = ''; + child.properties.style = child.properties.style.replace(COLOR_REG, (str) => { + color = str.replace(COLOR_REG, '$2'); + return str.replace(/(\);)/, '/ var(--bg-opacity)$1'); + }); + const tags = child.properties['data-lang']; const labelNode = { type: 'element', tagName: 'span', children: child.children, }; + const title = getCodeString(child.children); if (iconExist) { const svgNode = getSVGNode(iconPath); child.children = [...svgNode, labelNode]; @@ -39,8 +50,15 @@ export function homeCardIcons(node, parent, isHome) { const svgNode = getSVGNode(iconDefaultPath); child.children = [...svgNode, labelNode]; } + resultHomeCard[iconName] = { + md: iconName, + title: title, + rgb: color, + tags: tags ? tags.split('/') : [], + }; } return child; }); } + return resultHomeCard; }