Skip to content

Commit

Permalink
Merge branch 'develop' into fix-husky
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 committed Dec 22, 2023
2 parents 77111e6 + 167596b commit 907df62
Show file tree
Hide file tree
Showing 31 changed files with 1,002 additions and 3,010 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -5,8 +5,9 @@
/_playwright-results
/lib
/node_modules
/themes
/.husky/_

# exceptions
!.gitkeep
.vercel

4 changes: 2 additions & 2 deletions build/build.js
@@ -1,12 +1,12 @@
import path from 'path';
import { promises as fs } from 'fs';
import * as rollup from 'rollup';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import uglify from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';
import chokidar from 'chokidar';
import path from 'path';
import { relative } from './util.js';
import { promises as fs } from 'fs';

const pkgPath = relative(import.meta, '..', 'package.json');
const pkgString = (await fs.readFile(pkgPath)).toString();
Expand Down
1 change: 1 addition & 0 deletions build/cover.js
@@ -1,5 +1,6 @@
import fs from 'fs';
import { relative } from './util.js';

const read = fs.readFileSync;
const write = fs.writeFileSync;
const pkgPath = relative(import.meta, '..', 'package.json');
Expand Down
2 changes: 1 addition & 1 deletion build/emoji.js
@@ -1,6 +1,6 @@
import axios from 'axios';
import fs from 'fs';
import path from 'path';
import axios from 'axios';

const filePaths = {
emojiMarkdown: path.resolve(process.cwd(), 'docs', 'emoji.md'),
Expand Down
7 changes: 5 additions & 2 deletions build/mincss.js
@@ -1,14 +1,17 @@
import cssnano from 'cssnano';
import path from 'path';
import fs from 'fs';
import cssnano from 'cssnano';

const files = fs.readdirSync(path.resolve('lib/themes'));
const files = fs
.readdirSync(path.resolve('lib/themes'))
.filter(file => !file.endsWith('min.css'));

files.forEach(file => {
file = path.resolve('lib/themes', file);
cssnano
.process(fs.readFileSync(file))
.then(result => {
file = file.replace(/\.css$/, '.min.css');
fs.writeFileSync(file, result.css);
})
.catch(e => {
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration.md
Expand Up @@ -376,6 +376,8 @@ window.$docsify = {

Website logo as it appears in the sidebar. You can resize it using CSS.

!> Logo will only bee visible if `name` prop is also set. See [name](#name) configuration.

```js
window.$docsify = {
logo: '/_media/icon.svg',
Expand Down
34 changes: 15 additions & 19 deletions docs/index.html
Expand Up @@ -56,19 +56,22 @@
width: auto !important;
}
</style>
<script>
(function () {
const lang = location.hash.match(/#\/(de-de|es|ru-ru|zh-cn)\//);

// Set html "lang" attribute based on URL
if (lang) {
document.documentElement.setAttribute('lang', lang[1]);
}
})();
</script>
</head>

<body>
<div id="app">Loading ...</div>
<script src="//cdn.jsdelivr.net/npm/docsify-plugin-carbon@1"></script>
<script>
// Set html "lang" attribute based on URL
const lang = location.hash.match(/#\/(de-de|es|ru-ru|zh-cn)\//);

if (lang) {
document.documentElement.setAttribute('lang', lang[1]);
}

// Docsify configuration
window.$docsify = {
alias: {
Expand Down Expand Up @@ -184,7 +187,9 @@
},
},
plugins: [
DocsifyCarbon.create('CEBI6KQE', 'docsifyjsorg'),
function () {
DocsifyCarbon.create('CEBI6KQE', 'docsifyjsorg');
},
function (hook, vm) {
hook.beforeEach(html => {
if (/githubusercontent\.com/.test(vm.route.file)) {
Expand Down Expand Up @@ -214,21 +219,12 @@
</script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/docsify.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/search.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/ga.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/matomo.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-markdown.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-nginx.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-php.min.js"></script>
<script>
// Public site only
if (/docsify/.test(location.host)) {
document.write(
'<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/ga.min.js"><\/script>'
);
document.write(
'<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/matomo.min.js"><\/script>'
);
}
</script>
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
<!-- <script src="//cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script> -->
</body>
Expand Down
190 changes: 0 additions & 190 deletions index.html

This file was deleted.

6 changes: 5 additions & 1 deletion jest.config.js
@@ -1,5 +1,7 @@
import { TEST_HOST } from './test/config/server.js';
import { testConfig } from './server.configs.js';

const { hostname, port } = testConfig;
const TEST_HOST = `http://${hostname}:${port}`;
const sharedConfig = {
errorOnDeprecated: true,
globalSetup: './test/config/jest.setup.js',
Expand All @@ -11,6 +13,8 @@ const sharedConfig = {
testURL: `${TEST_HOST}/_blank.html`,
};

process.env.TEST_HOST = TEST_HOST;

export default {
transform: {},
projects: [
Expand Down
53 changes: 53 additions & 0 deletions middleware.js
@@ -0,0 +1,53 @@
// Exports
// =============================================================================
export const config = {
matcher: ['/preview/(index.html)?'],
};

// Rewrite rules shared with local server configurations
export const rewriteRules = [
// Replace CDN URLs with local paths
{
match: /https?.*\/CHANGELOG.md/g,
replace: '/CHANGELOG.md',
},
{
// CDN versioned default
// Ex1: //cdn.com/package-name
// Ex2: http://cdn.com/package-name@1.0.0
// Ex3: https://cdn.com/package-name@latest
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g,
replace: '/lib/docsify.min.js',
},
{
// CDN paths to local paths
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
// Ex2: http://cdn.com/package-name@1.0.0/dist/file.js => /dist/file.js
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g,
replace: '/lib/',
},
];

// Serve virtual /preview/index.html
// Note: See vercel.json for preview routing configuration
// 1. Fetch index.html from /docs/ directory
// 2. Replace CDN URLs with local paths (see rewriteRules)
// 3. Return preview HTML
export default async function middleware(request) {
const { origin } = new URL(request.url);
const indexURL = `${origin}/docs/index.html`;
const indexHTML = await fetch(indexURL).then(res => res.text());
const previewHTML = rewriteRules.reduce(
(html, rule) => html.replace(rule.match, rule.replace),
indexHTML
);

return new Response(previewHTML, {
status: 200,
headers: {
'content-type': 'text/html',
'x-robots-tag': 'noindex',
},
});
}

0 comments on commit 907df62

Please sign in to comment.