Skip to content

Commit 9e979f0

Browse files
committed
deploy: 5983792
1 parent bf66e41 commit 9e979f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+8319
-8867
lines changed

_ga.js

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
1-
// @deno-types="https://deno.land/x/types/react/v16.13.1/react.d.ts"
2-
3-
const Ga = ({ id }) => {
4-
React.useEffect(() => {
5-
window.addEventListener('rerender', () => {
6-
// @ts-ignore
7-
window.ga('set', 'page', location.pathname);
8-
window.ga('send', 'pageview');
9-
});
10-
}, []);
11-
return (React.createElement(React.Fragment, null,
12-
React.createElement("script", { async: true, src: "https://www.google-analytics.com/analytics.js" }),
13-
React.createElement("script", { dangerouslySetInnerHTML: {
14-
__html: `window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', '${id}');`
15-
} })));
16-
};
17-
export default Ga;
1+
import * as path from 'https://deno.land/[email protected]/path/mod.js';
2+
import * as fs from 'https://deno.land/[email protected]/fs/mod.js';
3+
import { green } from 'https://deno.land/[email protected]/fmt/colors.js';
4+
import * as ts from 'https://dev.jspm.io/[email protected]';
5+
/**
6+
* Compile input code from tsx to js, by typescript compiler
7+
* Will replace `.tsx` to `.js` in `import` statement, and remove react and react-dom imports
8+
*/
9+
export function compile(input) {
10+
return ts.default
11+
.transpileModule(input, {
12+
compilerOptions: {
13+
target: 'ESNext',
14+
module: 'ESNext',
15+
jsx: 'React',
16+
removeComments: false,
17+
newLine: 'lf'
18+
}
19+
})
20+
.outputText.replace(/(^import .*)\.tsx?((?:'|");?$)/gm, '$1.js$2')
21+
.replace(/(^import .*)\/react(\/|'|"|@).*$/gm, '')
22+
.replace(/(^import .*)\/react-dom(\/|'|"|@).*$/gm, '');
23+
}
24+
/**
25+
* Read input file and then compile it
26+
*/
27+
export async function compileFile(src) {
28+
console.log(green('Compile file'), src);
29+
const content = await fs.readFileStr(src);
30+
return compile(content);
31+
}
32+
/**
33+
* Compile a pagic file with local or remote url
34+
*/
35+
export async function compilePagicFile(pathToPagicRoot) {
36+
console.log(green('Compile pagic file'), pathToPagicRoot);
37+
let content = '';
38+
if (import.meta.url.startsWith('file://')) {
39+
const src = path.resolve(path.dirname(path.fromFileUrl(import.meta.url)), '../../', pathToPagicRoot);
40+
content = await fs.readFileStr(src);
41+
}
42+
else {
43+
const res = await fetch(import.meta.url.replace(/\/src\/utils\/mod\.ts$/, `/${pathToPagicRoot}`));
44+
content = await res.text();
45+
}
46+
return compile(content);
47+
}

_gitalk.js

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1-
// @deno-types="https://deno.land/x/types/react/v16.13.1/react.d.ts"
2-
3-
// @deno-types="https://deno.land/x/types/react-dom/v16.13.1/react-dom.d.ts"
4-
5-
const Gitalk = (props) => {
6-
React.useEffect(() => {
7-
// @ts-ignore
8-
const container = document.getElementById('gitalk-container');
9-
ReactDOM.unmountComponentAtNode(container);
10-
container.innerHTML = '';
11-
new window.Gitalk(props).render(container);
12-
}, [props.id]);
13-
return (React.createElement(React.Fragment, null,
14-
React.createElement("div", { id: "gitalk-container" }),
15-
React.createElement("link", { rel: "stylesheet", href: "https://unpkg.com/[email protected]/dist/gitalk.css" }),
16-
React.createElement("script", { src: "https://unpkg.com/[email protected]/dist/gitalk.min.js" })));
17-
};
18-
export default Gitalk;
1+
import * as path from 'https://deno.land/[email protected]/path/mod.js';
2+
import * as fs from 'https://deno.land/[email protected]/fs/mod.js';
3+
import { green } from 'https://deno.land/[email protected]/fmt/colors.js';
4+
import * as ts from 'https://dev.jspm.io/[email protected]';
5+
/**
6+
* Compile input code from tsx to js, by typescript compiler
7+
* Will replace `.tsx` to `.js` in `import` statement, and remove react and react-dom imports
8+
*/
9+
export function compile(input) {
10+
return ts.default
11+
.transpileModule(input, {
12+
compilerOptions: {
13+
target: 'ESNext',
14+
module: 'ESNext',
15+
jsx: 'React',
16+
removeComments: false,
17+
newLine: 'lf'
18+
}
19+
})
20+
.outputText.replace(/(^import .*)\.tsx?((?:'|");?$)/gm, '$1.js$2')
21+
.replace(/(^import .*)\/react(\/|'|"|@).*$/gm, '')
22+
.replace(/(^import .*)\/react-dom(\/|'|"|@).*$/gm, '');
23+
}
24+
/**
25+
* Read input file and then compile it
26+
*/
27+
export async function compileFile(src) {
28+
console.log(green('Compile file'), src);
29+
const content = await fs.readFileStr(src);
30+
return compile(content);
31+
}
32+
/**
33+
* Compile a pagic file with local or remote url
34+
*/
35+
export async function compilePagicFile(pathToPagicRoot) {
36+
console.log(green('Compile pagic file'), pathToPagicRoot);
37+
let content = '';
38+
if (import.meta.url.startsWith('file://')) {
39+
const src = path.resolve(path.dirname(path.fromFileUrl(import.meta.url)), '../../', pathToPagicRoot);
40+
content = await fs.readFileStr(src);
41+
}
42+
else {
43+
const res = await fetch(import.meta.url.replace(/\/src\/utils\/mod\.ts$/, `/${pathToPagicRoot}`));
44+
content = await res.text();
45+
}
46+
return compile(content);
47+
}

_layout.js

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
1-
// @deno-types="https://deno.land/x/types/react/v16.13.1/react.d.ts"
2-
3-
import Sidebar from './_sidebar.js';
4-
const Layout = ({ config, title, content, ga, gitalk, script, sidebar, outputPath }) => {
5-
const [isDark, setIsDark] = React.useState(
6-
// @ts-ignore
7-
window.Deno ? false : document.documentElement.classList.contains('is_dark'));
8-
return (React.createElement("html", { className: isDark ? 'is_dark' : '' },
9-
React.createElement("head", null,
10-
ga,
11-
React.createElement("title", null, outputPath !== 'index.html' ? `${title} · ${config.title}` : title),
12-
React.createElement("meta", { charSet: "utf-8" }),
13-
React.createElement("link", { id: "prismTheme", rel: "stylesheet", href: isDark ? `${config.base}assets/prism_tomorrow.css` : `${config.base}assets/prism.css` }),
14-
React.createElement("script", { dangerouslySetInnerHTML: {
15-
__html: `
16-
let shouldSetIsDark = document.cookie.includes('is_dark=1') ? true : document.cookie.includes('is_dark=0') ? false : window.matchMedia('(prefers-color-scheme: dark)').matches
17-
if (shouldSetIsDark) {
18-
document.documentElement.classList.add('is_dark');
19-
document.getElementById('prismTheme').href = "${config.base}assets/prism_tomorrow.css";
1+
import * as path from 'https://deno.land/[email protected]/path/mod.js';
2+
import * as fs from 'https://deno.land/[email protected]/fs/mod.js';
3+
import { green } from 'https://deno.land/[email protected]/fmt/colors.js';
4+
import * as ts from 'https://dev.jspm.io/[email protected]';
5+
/**
6+
* Compile input code from tsx to js, by typescript compiler
7+
* Will replace `.tsx` to `.js` in `import` statement, and remove react and react-dom imports
8+
*/
9+
export function compile(input) {
10+
return ts.default
11+
.transpileModule(input, {
12+
compilerOptions: {
13+
target: 'ESNext',
14+
module: 'ESNext',
15+
jsx: 'React',
16+
removeComments: false,
17+
newLine: 'lf'
18+
}
19+
})
20+
.outputText.replace(/(^import .*)\.tsx?((?:'|");?$)/gm, '$1.js$2')
21+
.replace(/(^import .*)\/react(\/|'|"|@).*$/gm, '')
22+
.replace(/(^import .*)\/react-dom(\/|'|"|@).*$/gm, '');
23+
}
24+
/**
25+
* Read input file and then compile it
26+
*/
27+
export async function compileFile(src) {
28+
console.log(green('Compile file'), src);
29+
const content = await fs.readFileStr(src);
30+
return compile(content);
31+
}
32+
/**
33+
* Compile a pagic file with local or remote url
34+
*/
35+
export async function compilePagicFile(pathToPagicRoot) {
36+
console.log(green('Compile pagic file'), pathToPagicRoot);
37+
let content = '';
38+
if (import.meta.url.startsWith('file://')) {
39+
const src = path.resolve(path.dirname(path.fromFileUrl(import.meta.url)), '../../', pathToPagicRoot);
40+
content = await fs.readFileStr(src);
41+
}
42+
else {
43+
const res = await fetch(import.meta.url.replace(/\/src\/utils\/mod\.ts$/, `/${pathToPagicRoot}`));
44+
content = await res.text();
45+
}
46+
return compile(content);
2047
}
21-
`
22-
} }),
23-
React.createElement("link", { rel: "stylesheet", href: `${config.base}assets/index.css` })),
24-
React.createElement("body", null,
25-
React.createElement("header", null,
26-
React.createElement("h1", null,
27-
React.createElement("a", { href: config.base }, config.title)),
28-
React.createElement("nav", null,
29-
React.createElement("ul", null,
30-
config.nav.map(({ text, link }) => (React.createElement("li", { key: link },
31-
React.createElement("a", { href: link }, text)))),
32-
React.createElement("li", null,
33-
React.createElement("a", { href: "#", onClick: (e) => {
34-
e.preventDefault();
35-
setIsDark(!isDark);
36-
// @ts-ignore
37-
document.cookie = `is_dark=${!isDark ? '1' : '0'}; expires=Tue, 19 Jun 2038 03:14:07 UTC; path=/`;
38-
} }, isDark ? '关闭黑暗模式' : '开启黑暗模式'))))),
39-
React.createElement(Sidebar, { sidebar: sidebar, outputPath: outputPath, config: config }),
40-
React.createElement("section", { className: "main" },
41-
content,
42-
gitalk),
43-
script)));
44-
};
45-
export default Layout;

_sidebar.js

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1-
// @deno-types="https://deno.land/x/types/react/v16.13.1/react.d.ts"
2-
3-
const Sidebar = ({ sidebar, outputPath, config }) => (React.createElement("aside", null,
4-
React.createElement("ul", null, sidebar.map(({ text, link, children }) => (React.createElement("li", { key: link },
5-
React.createElement("a", { href: `${config.base}${link}`, className: link === outputPath ? 'active' : '' }, text),
6-
children && (React.createElement("ul", null, children.map(({ text, link }) => (React.createElement("li", { key: link },
7-
React.createElement("a", { href: `${config.base}${link}`, className: link === outputPath ? 'active' : '' }, text))))))))))));
8-
export default Sidebar;
1+
import * as path from 'https://deno.land/[email protected]/path/mod.js';
2+
import * as fs from 'https://deno.land/[email protected]/fs/mod.js';
3+
import { green } from 'https://deno.land/[email protected]/fmt/colors.js';
4+
import * as ts from 'https://dev.jspm.io/[email protected]';
5+
/**
6+
* Compile input code from tsx to js, by typescript compiler
7+
* Will replace `.tsx` to `.js` in `import` statement, and remove react and react-dom imports
8+
*/
9+
export function compile(input) {
10+
return ts.default
11+
.transpileModule(input, {
12+
compilerOptions: {
13+
target: 'ESNext',
14+
module: 'ESNext',
15+
jsx: 'React',
16+
removeComments: false,
17+
newLine: 'lf'
18+
}
19+
})
20+
.outputText.replace(/(^import .*)\.tsx?((?:'|");?$)/gm, '$1.js$2')
21+
.replace(/(^import .*)\/react(\/|'|"|@).*$/gm, '')
22+
.replace(/(^import .*)\/react-dom(\/|'|"|@).*$/gm, '');
23+
}
24+
/**
25+
* Read input file and then compile it
26+
*/
27+
export async function compileFile(src) {
28+
console.log(green('Compile file'), src);
29+
const content = await fs.readFileStr(src);
30+
return compile(content);
31+
}
32+
/**
33+
* Compile a pagic file with local or remote url
34+
*/
35+
export async function compilePagicFile(pathToPagicRoot) {
36+
console.log(green('Compile pagic file'), pathToPagicRoot);
37+
let content = '';
38+
if (import.meta.url.startsWith('file://')) {
39+
const src = path.resolve(path.dirname(path.fromFileUrl(import.meta.url)), '../../', pathToPagicRoot);
40+
content = await fs.readFileStr(src);
41+
}
42+
else {
43+
const res = await fetch(import.meta.url.replace(/\/src\/utils\/mod\.ts$/, `/${pathToPagicRoot}`));
44+
content = await res.text();
45+
}
46+
return compile(content);
47+
}

advanced/class-and-interfaces.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<html class="" data-reactroot=""><head><script async="" src="https://www.google-analytics.com/analytics.js"></script><script>window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'UA-45256157-14');</script><title>类与接口 · TypeScript 入门教程</title><meta charSet="utf-8"/><link id="prismTheme" rel="stylesheet" href="/assets/prism.css"/><script>
1+
<html class="" data-reactroot=""><head><script async="" src="https://www.google-analytics.com/analytics.js"></script><script>
2+
window.GoogleAnalyticsObject="ga";(window.ga=window.ga||function(){(window.ga.q=window.ga.q||[]).push(arguments);}),(window.ga.l=1*new Date());
3+
4+
ga('create', 'UA-45256157-14', 'auto');
5+
ga('send', 'pageview');</script><title>类与接口 · TypeScript 入门教程</title><meta charSet="utf-8"/><link id="prismTheme" rel="stylesheet" href="/assets/prism.css"/><script>
26
let shouldSetIsDark = document.cookie.includes('is_dark=1') ? true : document.cookie.includes('is_dark=0') ? false : window.matchMedia('(prefers-color-scheme: dark)').matches
37
if (shouldSetIsDark) {
48
document.documentElement.classList.add('is_dark');

0 commit comments

Comments
 (0)