@brillout/docpress 0.10.8 → 0.10.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Layout.tsx +5 -2
- package/components/Link.tsx +62 -48
- package/components/RepoLink.tsx +1 -1
- package/dist/components/Link.d.ts +1 -1
- package/dist/components/Link.js +58 -30
- package/dist/components/RepoLink.d.ts +1 -1
- package/dist/types/Config.d.ts +1 -0
- package/dist/utils/assert.d.ts +1 -1
- package/dist/utils/assert.js +11 -12
- package/package.json +1 -1
- package/renderer/onRenderHtml.tsx +1 -1
- package/types/Config.ts +1 -0
- package/utils/assert.ts +11 -11
package/Layout.tsx
CHANGED
|
@@ -485,8 +485,11 @@ function NavLogo({ className }: { className: string }) {
|
|
|
485
485
|
>
|
|
486
486
|
<img
|
|
487
487
|
src={pageContext.meta.logoUrl}
|
|
488
|
-
|
|
489
|
-
|
|
488
|
+
style={{
|
|
489
|
+
height: iconSize,
|
|
490
|
+
width: iconSize,
|
|
491
|
+
...pageContext.config.navLogoStyle,
|
|
492
|
+
}}
|
|
490
493
|
onContextMenu={(ev) => {
|
|
491
494
|
if (!pageContext.config.pressKit) return // no /press page
|
|
492
495
|
if (window.location.pathname === '/press') return
|
package/components/Link.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import React from 'react'
|
|
|
5
5
|
import { isRepoLink, RepoLink } from './RepoLink'
|
|
6
6
|
import type { PageContextResolved } from '../config/resolvePageContext'
|
|
7
7
|
import { usePageContext } from '../renderer/usePageContext'
|
|
8
|
-
import { assert, assertUsage, determineSectionTitle, determineSectionUrlHash } from '../utils/server'
|
|
8
|
+
import { assert, assertUsage, assertWarning, determineSectionTitle, determineSectionUrlHash } from '../utils/server'
|
|
9
9
|
import { parseMarkdownMini } from '../parseMarkdownMini'
|
|
10
10
|
import pc from '@brillout/picocolors'
|
|
11
11
|
|
|
@@ -17,55 +17,86 @@ function Link({
|
|
|
17
17
|
children,
|
|
18
18
|
}: {
|
|
19
19
|
href: string
|
|
20
|
-
text?: string |
|
|
20
|
+
text?: string | React.ReactNode
|
|
21
21
|
noBreadcrumb?: true
|
|
22
22
|
doNotInferSectionTitle?: true
|
|
23
23
|
children?: React.ReactNode
|
|
24
24
|
}) {
|
|
25
|
+
const pageContext = usePageContext()
|
|
25
26
|
assertUsage(
|
|
26
27
|
href.startsWith('/') || href.startsWith('#'),
|
|
27
28
|
`<Link href /> prop \`href==='${href}'\` but should start with '/' or '#'`,
|
|
28
29
|
)
|
|
29
30
|
assertUsage(!text || !children, 'Cannot use both `text` or `children`')
|
|
31
|
+
assertWarning(!text, 'prop `text` is deprecated')
|
|
32
|
+
text = text ?? children
|
|
30
33
|
|
|
31
34
|
if (isRepoLink(href)) {
|
|
32
35
|
return <RepoLink path={href} text={text} />
|
|
33
36
|
} else {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
)
|
|
37
|
+
const linkTextData = getLinkTextData(href, pageContext, doNotInferSectionTitle)
|
|
38
|
+
if (!linkTextData) {
|
|
39
|
+
text = 'LINK-TARGET-NOT-FOUND'
|
|
40
|
+
} else if (!text) {
|
|
41
|
+
text = getLinkText({
|
|
42
|
+
noBreadcrumb,
|
|
43
|
+
...linkTextData,
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
return <a href={href}>{text}</a>
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
function getLinkText({
|
|
42
|
-
href,
|
|
43
51
|
noBreadcrumb,
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
linkData,
|
|
53
|
+
sectionTitle,
|
|
54
|
+
isLinkOnSamePage,
|
|
46
55
|
}: {
|
|
47
|
-
href: string
|
|
48
56
|
noBreadcrumb: true | undefined
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
linkData: LinkData
|
|
58
|
+
sectionTitle: JSX.Element | null
|
|
59
|
+
isLinkOnSamePage: boolean
|
|
51
60
|
}): JSX.Element {
|
|
52
|
-
const { hrefPathname, hrefHash } = parseHref(href)
|
|
53
|
-
|
|
54
|
-
const linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext)
|
|
55
|
-
const isLinkOnSamePage = linkData.url === pageContext.urlPathname
|
|
56
|
-
if (!hrefPathname) assert(isLinkOnSamePage)
|
|
57
|
-
|
|
58
61
|
const breadcrumbParts: JSX.Element[] = []
|
|
59
62
|
if (linkData.linkBreadcrumb) {
|
|
60
63
|
breadcrumbParts.push(...(linkData.linkBreadcrumb ?? []).slice().reverse().map(parseMarkdownMini))
|
|
61
64
|
}
|
|
62
65
|
breadcrumbParts.push(parseMarkdownMini(linkData.title))
|
|
66
|
+
if (sectionTitle) breadcrumbParts.push(sectionTitle)
|
|
67
|
+
|
|
68
|
+
if (noBreadcrumb || isLinkOnSamePage) {
|
|
69
|
+
return breadcrumbParts[breadcrumbParts.length - 1]
|
|
70
|
+
}
|
|
71
|
+
return (
|
|
72
|
+
<>
|
|
73
|
+
{breadcrumbParts.map((title, i) => {
|
|
74
|
+
const seperator = i === 0 ? <></> : ' > '
|
|
75
|
+
return (
|
|
76
|
+
<React.Fragment key={i}>
|
|
77
|
+
{seperator}
|
|
78
|
+
{title}
|
|
79
|
+
</React.Fragment>
|
|
80
|
+
)
|
|
81
|
+
})}
|
|
82
|
+
</>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getLinkTextData(href: string, pageContext: PageContextResolved, doNotInferSectionTitle?: boolean) {
|
|
87
|
+
const { hrefPathname, hrefHash } = parseHref(href)
|
|
63
88
|
|
|
89
|
+
const linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext)
|
|
90
|
+
assert(linkData)
|
|
91
|
+
const isLinkOnSamePage = linkData.url === pageContext.urlPathname
|
|
92
|
+
if (!hrefPathname) assert(isLinkOnSamePage)
|
|
93
|
+
|
|
94
|
+
let sectionTitle: JSX.Element | null = null
|
|
64
95
|
if (hrefHash) {
|
|
65
|
-
let sectionTitle: JSX.Element | undefined = undefined
|
|
66
96
|
assert(!hrefHash.startsWith('#'))
|
|
67
97
|
if (isLinkOnSamePage) {
|
|
68
98
|
const linkDataPageSection = findLinkData(`#${hrefHash}`, pageContext)
|
|
99
|
+
if (!linkDataPageSection) return null
|
|
69
100
|
sectionTitle = parseMarkdownMini(linkDataPageSection.title)
|
|
70
101
|
} else if ('sectionTitles' in linkData && linkData.sectionTitles) {
|
|
71
102
|
linkData.sectionTitles.forEach((title) => {
|
|
@@ -75,34 +106,18 @@ function getLinkText({
|
|
|
75
106
|
})
|
|
76
107
|
}
|
|
77
108
|
if (!sectionTitle) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
109
|
+
if (doNotInferSectionTitle) {
|
|
110
|
+
assertWarning(
|
|
111
|
+
false,
|
|
112
|
+
`Page section title not found for <Link href="\`${href}\`" doNotInferSectionTitle={true} />.`,
|
|
113
|
+
)
|
|
114
|
+
return null
|
|
115
|
+
}
|
|
82
116
|
sectionTitle = <>{determineSectionTitle(href)}</>
|
|
83
117
|
}
|
|
84
|
-
breadcrumbParts.push(sectionTitle)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
if (noBreadcrumb || isLinkOnSamePage) {
|
|
89
|
-
return breadcrumbParts[breadcrumbParts.length - 1]
|
|
90
|
-
}
|
|
91
118
|
}
|
|
92
119
|
|
|
93
|
-
return
|
|
94
|
-
<>
|
|
95
|
-
{breadcrumbParts.map((title, i) => {
|
|
96
|
-
const seperator = i === 0 ? <></> : ' > '
|
|
97
|
-
return (
|
|
98
|
-
<React.Fragment key={i}>
|
|
99
|
-
{seperator}
|
|
100
|
-
{title}
|
|
101
|
-
</React.Fragment>
|
|
102
|
-
)
|
|
103
|
-
})}
|
|
104
|
-
</>
|
|
105
|
-
)
|
|
120
|
+
return { linkData, sectionTitle, isLinkOnSamePage }
|
|
106
121
|
}
|
|
107
122
|
|
|
108
123
|
type LinkData = {
|
|
@@ -111,15 +126,14 @@ type LinkData = {
|
|
|
111
126
|
linkBreadcrumb: null | string[]
|
|
112
127
|
sectionTitles?: string[]
|
|
113
128
|
}
|
|
114
|
-
|
|
115
|
-
function findLinkData(href: string, pageContext: PageContextResolved): LinkData {
|
|
129
|
+
function findLinkData(href: string, pageContext: PageContextResolved): LinkData | null {
|
|
116
130
|
assert(href.startsWith('/') || href.startsWith('#'))
|
|
117
131
|
const { linksAll } = pageContext
|
|
118
132
|
const linkData = linksAll.find(({ url }) => href === url)
|
|
119
133
|
if (href.startsWith('#')) {
|
|
120
|
-
|
|
134
|
+
assertWarning(linkData, `Couldn't find ${href} in ${pageContext.urlPathname}, does it exist?`)
|
|
121
135
|
} else {
|
|
122
|
-
|
|
136
|
+
assertWarning(
|
|
123
137
|
linkData,
|
|
124
138
|
[
|
|
125
139
|
`Couldn't find page with URL ${pc.bold(href)}`,
|
|
@@ -136,7 +150,7 @@ function findLinkData(href: string, pageContext: PageContextResolved): LinkData
|
|
|
136
150
|
].join(' '),
|
|
137
151
|
)
|
|
138
152
|
}
|
|
139
|
-
return linkData
|
|
153
|
+
return linkData ?? null
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
function parseHref(href: string) {
|
package/components/RepoLink.tsx
CHANGED
|
@@ -10,7 +10,7 @@ function isRepoLink(href: string) {
|
|
|
10
10
|
return ['/examples/', '/docs/', '/boilerplates/', '.github/', '/test/'].some((start) => href.startsWith(start))
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function RepoLink({ path, text, editMode }: { path: string; text?: string |
|
|
13
|
+
function RepoLink({ path, text, editMode }: { path: string; text?: string | React.ReactNode; editMode?: true }) {
|
|
14
14
|
text = text || path
|
|
15
15
|
const href = getRepoHref(path, editMode)
|
|
16
16
|
return <a href={href}>{text}</a>
|
|
@@ -3,7 +3,7 @@ export type { LinkData };
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
declare function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, children, }: {
|
|
5
5
|
href: string;
|
|
6
|
-
text?: string |
|
|
6
|
+
text?: string | React.ReactNode;
|
|
7
7
|
noBreadcrumb?: true;
|
|
8
8
|
doNotInferSectionTitle?: true;
|
|
9
9
|
children?: React.ReactNode;
|
package/dist/components/Link.js
CHANGED
|
@@ -1,66 +1,94 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
1
12
|
export { Link };
|
|
2
13
|
import React from 'react';
|
|
3
14
|
import { isRepoLink, RepoLink } from './RepoLink';
|
|
4
15
|
import { usePageContext } from '../renderer/usePageContext';
|
|
5
|
-
import { assert, assertUsage, determineSectionTitle, determineSectionUrlHash } from '../utils/server';
|
|
16
|
+
import { assert, assertUsage, assertWarning, determineSectionTitle, determineSectionUrlHash } from '../utils/server';
|
|
6
17
|
import { parseMarkdownMini } from '../parseMarkdownMini';
|
|
7
18
|
import pc from '@brillout/picocolors';
|
|
8
19
|
function Link(_a) {
|
|
9
20
|
var href = _a.href, text = _a.text, noBreadcrumb = _a.noBreadcrumb, doNotInferSectionTitle = _a.doNotInferSectionTitle, children = _a.children;
|
|
21
|
+
var pageContext = usePageContext();
|
|
10
22
|
assertUsage(href.startsWith('/') || href.startsWith('#'), "<Link href /> prop `href==='".concat(href, "'` but should start with '/' or '#'"));
|
|
11
23
|
assertUsage(!text || !children, 'Cannot use both `text` or `children`');
|
|
24
|
+
assertWarning(!text, 'prop `text` is deprecated');
|
|
25
|
+
text = text !== null && text !== void 0 ? text : children;
|
|
12
26
|
if (isRepoLink(href)) {
|
|
13
27
|
return React.createElement(RepoLink, { path: href, text: text });
|
|
14
28
|
}
|
|
15
29
|
else {
|
|
16
|
-
var
|
|
17
|
-
|
|
30
|
+
var linkTextData = getLinkTextData(href, pageContext, doNotInferSectionTitle);
|
|
31
|
+
if (!linkTextData) {
|
|
32
|
+
text = 'LINK-TARGET-NOT-FOUND';
|
|
33
|
+
}
|
|
34
|
+
else if (!text) {
|
|
35
|
+
text = getLinkText(__assign({ noBreadcrumb: noBreadcrumb }, linkTextData));
|
|
36
|
+
}
|
|
37
|
+
return React.createElement("a", { href: href }, text);
|
|
18
38
|
}
|
|
19
39
|
}
|
|
20
40
|
function getLinkText(_a) {
|
|
21
41
|
var _b;
|
|
22
|
-
var
|
|
23
|
-
var _c = parseHref(href), hrefPathname = _c.hrefPathname, hrefHash = _c.hrefHash;
|
|
24
|
-
var linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext);
|
|
25
|
-
var isLinkOnSamePage = linkData.url === pageContext.urlPathname;
|
|
26
|
-
if (!hrefPathname)
|
|
27
|
-
assert(isLinkOnSamePage);
|
|
42
|
+
var noBreadcrumb = _a.noBreadcrumb, linkData = _a.linkData, sectionTitle = _a.sectionTitle, isLinkOnSamePage = _a.isLinkOnSamePage;
|
|
28
43
|
var breadcrumbParts = [];
|
|
29
44
|
if (linkData.linkBreadcrumb) {
|
|
30
45
|
breadcrumbParts.push.apply(breadcrumbParts, ((_b = linkData.linkBreadcrumb) !== null && _b !== void 0 ? _b : []).slice().reverse().map(parseMarkdownMini));
|
|
31
46
|
}
|
|
32
47
|
breadcrumbParts.push(parseMarkdownMini(linkData.title));
|
|
48
|
+
if (sectionTitle)
|
|
49
|
+
breadcrumbParts.push(sectionTitle);
|
|
50
|
+
if (noBreadcrumb || isLinkOnSamePage) {
|
|
51
|
+
return breadcrumbParts[breadcrumbParts.length - 1];
|
|
52
|
+
}
|
|
53
|
+
return (React.createElement(React.Fragment, null, breadcrumbParts.map(function (title, i) {
|
|
54
|
+
var seperator = i === 0 ? React.createElement(React.Fragment, null) : ' > ';
|
|
55
|
+
return (React.createElement(React.Fragment, { key: i },
|
|
56
|
+
seperator,
|
|
57
|
+
title));
|
|
58
|
+
})));
|
|
59
|
+
}
|
|
60
|
+
function getLinkTextData(href, pageContext, doNotInferSectionTitle) {
|
|
61
|
+
var _a = parseHref(href), hrefPathname = _a.hrefPathname, hrefHash = _a.hrefHash;
|
|
62
|
+
var linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext);
|
|
63
|
+
assert(linkData);
|
|
64
|
+
var isLinkOnSamePage = linkData.url === pageContext.urlPathname;
|
|
65
|
+
if (!hrefPathname)
|
|
66
|
+
assert(isLinkOnSamePage);
|
|
67
|
+
var sectionTitle = null;
|
|
33
68
|
if (hrefHash) {
|
|
34
|
-
var sectionTitle_1 = undefined;
|
|
35
69
|
assert(!hrefHash.startsWith('#'));
|
|
36
70
|
if (isLinkOnSamePage) {
|
|
37
71
|
var linkDataPageSection = findLinkData("#".concat(hrefHash), pageContext);
|
|
38
|
-
|
|
72
|
+
if (!linkDataPageSection)
|
|
73
|
+
return null;
|
|
74
|
+
sectionTitle = parseMarkdownMini(linkDataPageSection.title);
|
|
39
75
|
}
|
|
40
76
|
else if ('sectionTitles' in linkData && linkData.sectionTitles) {
|
|
41
77
|
linkData.sectionTitles.forEach(function (title) {
|
|
42
78
|
if (determineSectionUrlHash(title) === hrefHash) {
|
|
43
|
-
|
|
79
|
+
sectionTitle = parseMarkdownMini(title);
|
|
44
80
|
}
|
|
45
81
|
});
|
|
46
82
|
}
|
|
47
|
-
if (!
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
if (noBreadcrumb || isLinkOnSamePage) {
|
|
55
|
-
return breadcrumbParts[breadcrumbParts.length - 1];
|
|
83
|
+
if (!sectionTitle) {
|
|
84
|
+
if (doNotInferSectionTitle) {
|
|
85
|
+
assertWarning(false, "Page section title not found for <Link href=\"`".concat(href, "`\" doNotInferSectionTitle={true} />."));
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
sectionTitle = React.createElement(React.Fragment, null, determineSectionTitle(href));
|
|
56
89
|
}
|
|
57
90
|
}
|
|
58
|
-
return
|
|
59
|
-
var seperator = i === 0 ? React.createElement(React.Fragment, null) : ' > ';
|
|
60
|
-
return (React.createElement(React.Fragment, { key: i },
|
|
61
|
-
seperator,
|
|
62
|
-
title));
|
|
63
|
-
})));
|
|
91
|
+
return { linkData: linkData, sectionTitle: sectionTitle, isLinkOnSamePage: isLinkOnSamePage };
|
|
64
92
|
}
|
|
65
93
|
function findLinkData(href, pageContext) {
|
|
66
94
|
assert(href.startsWith('/') || href.startsWith('#'));
|
|
@@ -70,10 +98,10 @@ function findLinkData(href, pageContext) {
|
|
|
70
98
|
return href === url;
|
|
71
99
|
});
|
|
72
100
|
if (href.startsWith('#')) {
|
|
73
|
-
|
|
101
|
+
assertWarning(linkData, "Couldn't find ".concat(href, " in ").concat(pageContext.urlPathname, ", does it exist?"));
|
|
74
102
|
}
|
|
75
103
|
else {
|
|
76
|
-
|
|
104
|
+
assertWarning(linkData, [
|
|
77
105
|
"Couldn't find page with URL ".concat(pc.bold(href)),
|
|
78
106
|
"\u2014 did you define it in",
|
|
79
107
|
[
|
|
@@ -87,7 +115,7 @@ function findLinkData(href, pageContext) {
|
|
|
87
115
|
].join(''),
|
|
88
116
|
].join(' '));
|
|
89
117
|
}
|
|
90
|
-
return linkData;
|
|
118
|
+
return linkData !== null && linkData !== void 0 ? linkData : null;
|
|
91
119
|
}
|
|
92
120
|
function parseHref(href) {
|
|
93
121
|
var hrefHash = null;
|
|
@@ -5,7 +5,7 @@ export { getRepoHref };
|
|
|
5
5
|
declare function isRepoLink(href: string): boolean;
|
|
6
6
|
declare function RepoLink({ path, text, editMode }: {
|
|
7
7
|
path: string;
|
|
8
|
-
text?: string |
|
|
8
|
+
text?: string | React.ReactNode;
|
|
9
9
|
editMode?: true;
|
|
10
10
|
}): React.JSX.Element;
|
|
11
11
|
declare function getRepoHref(path: string, editMode?: true): string;
|
package/dist/types/Config.d.ts
CHANGED
package/dist/utils/assert.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { assertUsage };
|
|
|
3
3
|
export { assertWarning };
|
|
4
4
|
declare function assert(condition: unknown, debugInfo?: unknown): asserts condition;
|
|
5
5
|
declare function assertUsage(condition: unknown, msg: string): asserts condition;
|
|
6
|
-
declare function assertWarning(condition: unknown, msg: string):
|
|
6
|
+
declare function assertWarning(condition: unknown, msg: string): void;
|
package/dist/utils/assert.js
CHANGED
|
@@ -12,12 +12,12 @@ if (isBrowser()) {
|
|
|
12
12
|
]
|
|
13
13
|
.filter(Boolean)
|
|
14
14
|
.join(' '));
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
15
|
+
}
|
|
16
|
+
if (isDevMode()) {
|
|
17
|
+
window.onerror = function (err) {
|
|
18
|
+
window.alert(err);
|
|
19
|
+
window.onerror = null;
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
function assert(condition, debugInfo) {
|
|
23
23
|
if (condition) {
|
|
@@ -48,7 +48,7 @@ function isBrowser() {
|
|
|
48
48
|
return typeof window !== 'undefined';
|
|
49
49
|
}
|
|
50
50
|
function isDevMode() {
|
|
51
|
-
return !!window.localStorage[devModeKey] || isLocalhost();
|
|
51
|
+
return isBrowser() && (!!window.localStorage[devModeKey] || isLocalhost());
|
|
52
52
|
}
|
|
53
53
|
function isLocalhost() {
|
|
54
54
|
var _a;
|
|
@@ -71,10 +71,9 @@ function assertWarning(condition, msg) {
|
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
msg = '[DocPress][Warning] ' + msg;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.warn(msg);
|
|
74
|
+
var err = new Error(msg);
|
|
75
|
+
console.warn(err);
|
|
76
|
+
if (isDevMode()) {
|
|
77
|
+
window.alert(err);
|
|
79
78
|
}
|
|
80
79
|
}
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ Promise<Awaited<ReturnType<OnRenderHtmlAsync>>> => {
|
|
|
27
27
|
<html>
|
|
28
28
|
<head>
|
|
29
29
|
<meta charset="UTF-8" />
|
|
30
|
-
<link rel="icon" href="${faviconUrl}" />
|
|
30
|
+
<link rel="icon" href="${faviconUrl ?? ''}" />
|
|
31
31
|
<title>${pageContextResolved.documentTitle}</title>
|
|
32
32
|
${descriptionTag}
|
|
33
33
|
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
|
package/types/Config.ts
CHANGED
package/utils/assert.ts
CHANGED
|
@@ -15,11 +15,11 @@ if (isBrowser()) {
|
|
|
15
15
|
.filter(Boolean)
|
|
16
16
|
.join(' '),
|
|
17
17
|
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
}
|
|
19
|
+
if (isDevMode()) {
|
|
20
|
+
window.onerror = (err) => {
|
|
21
|
+
window.alert(err)
|
|
22
|
+
window.onerror = null
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -54,7 +54,7 @@ function isBrowser() {
|
|
|
54
54
|
return typeof window !== 'undefined'
|
|
55
55
|
}
|
|
56
56
|
function isDevMode() {
|
|
57
|
-
return !!window.localStorage[devModeKey] || isLocalhost()
|
|
57
|
+
return isBrowser() && (!!window.localStorage[devModeKey] || isLocalhost())
|
|
58
58
|
}
|
|
59
59
|
function isLocalhost() {
|
|
60
60
|
return window?.location?.port !== ''
|
|
@@ -70,14 +70,14 @@ function toggleDevMode() {
|
|
|
70
70
|
console.log(`DEV MODE ${isEnabled() ? 'enabled' : 'disabled'}`)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function assertWarning(condition: unknown, msg: string)
|
|
73
|
+
function assertWarning(condition: unknown, msg: string) {
|
|
74
74
|
if (condition) {
|
|
75
75
|
return
|
|
76
76
|
}
|
|
77
77
|
msg = '[DocPress][Warning] ' + msg
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
const err = new Error(msg)
|
|
79
|
+
console.warn(err)
|
|
80
|
+
if (isDevMode()) {
|
|
81
|
+
window.alert(err)
|
|
82
82
|
}
|
|
83
83
|
}
|