@brillout/docpress 0.12.4 → 0.12.6
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/components/Algolia/Hit.tsx +1 -1
- package/components/Link.tsx +53 -31
- package/css/code/block.css +18 -11
- package/dist/components/Link.d.ts +4 -3
- package/dist/components/Link.js +34 -26
- package/docsearch/DocSearchInstall.tsx +8 -0
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ type HierarchyType = Exclude<DocSearchHit['type'], 'content'>
|
|
|
14
14
|
|
|
15
15
|
function Hit({ hit }: HitProps) {
|
|
16
16
|
return (
|
|
17
|
-
<a href={hit.
|
|
17
|
+
<a href={hit.url}>
|
|
18
18
|
<div className="DocSearch-Hit-Container">
|
|
19
19
|
{(hit as InternalDocSearchHit).__docsearch_parent && (
|
|
20
20
|
<svg className="DocSearch-Hit-Tree" viewBox="0 0 24 54">
|
package/components/Link.tsx
CHANGED
|
@@ -13,12 +13,14 @@ function Link({
|
|
|
13
13
|
text,
|
|
14
14
|
noBreadcrumb,
|
|
15
15
|
doNotInferSectionTitle,
|
|
16
|
+
noWarning,
|
|
16
17
|
children,
|
|
17
18
|
}: {
|
|
18
19
|
href: string
|
|
19
20
|
text?: string | React.ReactNode
|
|
20
|
-
noBreadcrumb?:
|
|
21
|
-
doNotInferSectionTitle?:
|
|
21
|
+
noBreadcrumb?: boolean
|
|
22
|
+
doNotInferSectionTitle?: boolean
|
|
23
|
+
noWarning?: boolean
|
|
22
24
|
children?: React.ReactNode
|
|
23
25
|
}) {
|
|
24
26
|
const pageContext = usePageContext()
|
|
@@ -30,15 +32,18 @@ function Link({
|
|
|
30
32
|
// assertWarning(!text, 'prop `text` is deprecated')
|
|
31
33
|
text = text ?? children
|
|
32
34
|
|
|
33
|
-
const linkTextData = getLinkTextData(href, pageContext, doNotInferSectionTitle)
|
|
34
|
-
if (!
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
35
|
+
const linkTextData = getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning })
|
|
36
|
+
if (!text) {
|
|
37
|
+
if (linkTextData) {
|
|
38
|
+
text = getLinkText({
|
|
39
|
+
noBreadcrumb,
|
|
40
|
+
...linkTextData,
|
|
41
|
+
})
|
|
42
|
+
} else {
|
|
43
|
+
text = 'LINK-TARGET-NOT-FOUND'
|
|
44
|
+
}
|
|
41
45
|
}
|
|
46
|
+
|
|
42
47
|
return <a href={href}>{text}</a>
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -48,7 +53,7 @@ function getLinkText({
|
|
|
48
53
|
sectionTitle,
|
|
49
54
|
isLinkOnSamePage,
|
|
50
55
|
}: {
|
|
51
|
-
noBreadcrumb:
|
|
56
|
+
noBreadcrumb: boolean | undefined
|
|
52
57
|
linkData: LinkData
|
|
53
58
|
sectionTitle: React.JSX.Element | null
|
|
54
59
|
isLinkOnSamePage: boolean
|
|
@@ -78,10 +83,20 @@ function getLinkText({
|
|
|
78
83
|
)
|
|
79
84
|
}
|
|
80
85
|
|
|
81
|
-
function getLinkTextData(
|
|
86
|
+
function getLinkTextData({
|
|
87
|
+
href,
|
|
88
|
+
pageContext,
|
|
89
|
+
doNotInferSectionTitle,
|
|
90
|
+
noWarning,
|
|
91
|
+
}: {
|
|
92
|
+
href: string
|
|
93
|
+
pageContext: PageContextResolved
|
|
94
|
+
doNotInferSectionTitle?: boolean
|
|
95
|
+
noWarning?: boolean
|
|
96
|
+
}) {
|
|
82
97
|
const { hrefPathname, hrefHash } = parseHref(href)
|
|
83
98
|
|
|
84
|
-
const linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext)
|
|
99
|
+
const linkData = findLinkData(hrefPathname || pageContext.urlPathname, { pageContext, noWarning })
|
|
85
100
|
if (!linkData) return null
|
|
86
101
|
const isLinkOnSamePage = linkData.url === pageContext.urlPathname
|
|
87
102
|
if (!hrefPathname) assert(isLinkOnSamePage)
|
|
@@ -90,7 +105,7 @@ function getLinkTextData(href: string, pageContext: PageContextResolved, doNotIn
|
|
|
90
105
|
if (hrefHash) {
|
|
91
106
|
assert(!hrefHash.startsWith('#'))
|
|
92
107
|
if (isLinkOnSamePage) {
|
|
93
|
-
const linkDataPageSection = findLinkData(`#${hrefHash}`, pageContext)
|
|
108
|
+
const linkDataPageSection = findLinkData(`#${hrefHash}`, { pageContext, noWarning })
|
|
94
109
|
if (!linkDataPageSection) return null
|
|
95
110
|
sectionTitle = parseMarkdownMini(linkDataPageSection.title)
|
|
96
111
|
} else if ('sectionTitles' in linkData && linkData.sectionTitles) {
|
|
@@ -121,29 +136,36 @@ type LinkData = {
|
|
|
121
136
|
linkBreadcrumb: null | string[]
|
|
122
137
|
sectionTitles?: string[]
|
|
123
138
|
}
|
|
124
|
-
function findLinkData(
|
|
139
|
+
function findLinkData(
|
|
140
|
+
href: string,
|
|
141
|
+
{ pageContext, noWarning }: { pageContext: PageContextResolved; noWarning?: boolean },
|
|
142
|
+
): LinkData | null {
|
|
125
143
|
assert(href.startsWith('/') || href.startsWith('#'))
|
|
126
144
|
const { linksAll } = pageContext
|
|
127
145
|
const linkData = linksAll.find(({ url }) => href === url)
|
|
128
146
|
if (href.startsWith('#')) {
|
|
129
|
-
|
|
147
|
+
if (!noWarning) {
|
|
148
|
+
assertWarning(linkData, `Couldn't find ${href} in ${pageContext.urlPathname}, does it exist?`)
|
|
149
|
+
}
|
|
130
150
|
} else {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
`Couldn't find page with URL ${pc.bold(href)}`,
|
|
135
|
-
`— did you define it in`,
|
|
151
|
+
if (!noWarning) {
|
|
152
|
+
assertWarning(
|
|
153
|
+
linkData,
|
|
136
154
|
[
|
|
137
|
-
pc.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
`Couldn't find page with URL ${pc.bold(href)}`,
|
|
156
|
+
`— did you define it in`,
|
|
157
|
+
[
|
|
158
|
+
pc.cyan('docpress.config.js'),
|
|
159
|
+
pc.dim('#{'),
|
|
160
|
+
pc.cyan('headings'),
|
|
161
|
+
pc.dim(','),
|
|
162
|
+
pc.cyan('headingsDetached'),
|
|
163
|
+
pc.dim('}'),
|
|
164
|
+
'?',
|
|
165
|
+
].join(''),
|
|
166
|
+
].join(' '),
|
|
167
|
+
)
|
|
168
|
+
}
|
|
147
169
|
}
|
|
148
170
|
return linkData ?? null
|
|
149
171
|
}
|
package/css/code/block.css
CHANGED
|
@@ -32,18 +32,25 @@ figure[data-rehype-pretty-code-figure] {
|
|
|
32
32
|
font-size: 0.8em !important;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/* `@media (pointer: fine)`
|
|
36
|
+
* - Further reduce code block font size only on mobile.
|
|
37
|
+
* - https://github.com/vikejs/vike/issues/2369#issuecomment-2803046966
|
|
38
|
+
* - https://stackoverflow.com/questions/23885255/how-to-remove-ignore-hover-css-style-on-touch-devices/64553121#64553121
|
|
39
|
+
*/
|
|
40
|
+
@media not all and (hover: hover) and (pointer: fine) {
|
|
41
|
+
@container container-viewport (max-width: 620px) {
|
|
42
|
+
pre > code {
|
|
43
|
+
font-size: 0.7em !important;
|
|
44
|
+
}
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
@container container-viewport (max-width: 550px) {
|
|
47
|
+
pre > code {
|
|
48
|
+
font-size: 0.6em !important;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
@container container-viewport (max-width: 450px) {
|
|
52
|
+
pre > code {
|
|
53
|
+
font-size: 0.5em !important;
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { Link };
|
|
2
2
|
export type { LinkData };
|
|
3
3
|
import React from 'react';
|
|
4
|
-
declare function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, children, }: {
|
|
4
|
+
declare function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, noWarning, children, }: {
|
|
5
5
|
href: string;
|
|
6
6
|
text?: string | React.ReactNode;
|
|
7
|
-
noBreadcrumb?:
|
|
8
|
-
doNotInferSectionTitle?:
|
|
7
|
+
noBreadcrumb?: boolean;
|
|
8
|
+
doNotInferSectionTitle?: boolean;
|
|
9
|
+
noWarning?: boolean;
|
|
9
10
|
children?: React.ReactNode;
|
|
10
11
|
}): React.JSX.Element;
|
|
11
12
|
type LinkData = {
|
package/dist/components/Link.js
CHANGED
|
@@ -16,18 +16,20 @@ import { assert, assertUsage, assertWarning, determineSectionTitle, determineSec
|
|
|
16
16
|
import { parseMarkdownMini } from '../parseMarkdownMini';
|
|
17
17
|
import pc from '@brillout/picocolors';
|
|
18
18
|
function Link(_a) {
|
|
19
|
-
var href = _a.href, text = _a.text, noBreadcrumb = _a.noBreadcrumb, doNotInferSectionTitle = _a.doNotInferSectionTitle, children = _a.children;
|
|
19
|
+
var href = _a.href, text = _a.text, noBreadcrumb = _a.noBreadcrumb, doNotInferSectionTitle = _a.doNotInferSectionTitle, noWarning = _a.noWarning, children = _a.children;
|
|
20
20
|
var pageContext = usePageContext();
|
|
21
21
|
assertUsage(href.startsWith('/') || href.startsWith('#'), "<Link href /> prop `href==='".concat(href, "'` but should start with '/' or '#'"));
|
|
22
22
|
assertUsage(!text || !children, 'Cannot use both `text` or `children`');
|
|
23
23
|
// assertWarning(!text, 'prop `text` is deprecated')
|
|
24
24
|
text = text !== null && text !== void 0 ? text : children;
|
|
25
|
-
var linkTextData = getLinkTextData(href, pageContext, doNotInferSectionTitle);
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
var linkTextData = getLinkTextData({ href: href, pageContext: pageContext, doNotInferSectionTitle: doNotInferSectionTitle, noWarning: noWarning });
|
|
26
|
+
if (!text) {
|
|
27
|
+
if (linkTextData) {
|
|
28
|
+
text = getLinkText(__assign({ noBreadcrumb: noBreadcrumb }, linkTextData));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
text = 'LINK-TARGET-NOT-FOUND';
|
|
32
|
+
}
|
|
31
33
|
}
|
|
32
34
|
return React.createElement("a", { href: href }, text);
|
|
33
35
|
}
|
|
@@ -51,9 +53,10 @@ function getLinkText(_a) {
|
|
|
51
53
|
title));
|
|
52
54
|
})));
|
|
53
55
|
}
|
|
54
|
-
function getLinkTextData(
|
|
55
|
-
var
|
|
56
|
-
var
|
|
56
|
+
function getLinkTextData(_a) {
|
|
57
|
+
var href = _a.href, pageContext = _a.pageContext, doNotInferSectionTitle = _a.doNotInferSectionTitle, noWarning = _a.noWarning;
|
|
58
|
+
var _b = parseHref(href), hrefPathname = _b.hrefPathname, hrefHash = _b.hrefHash;
|
|
59
|
+
var linkData = findLinkData(hrefPathname || pageContext.urlPathname, { pageContext: pageContext, noWarning: noWarning });
|
|
57
60
|
if (!linkData)
|
|
58
61
|
return null;
|
|
59
62
|
var isLinkOnSamePage = linkData.url === pageContext.urlPathname;
|
|
@@ -63,7 +66,7 @@ function getLinkTextData(href, pageContext, doNotInferSectionTitle) {
|
|
|
63
66
|
if (hrefHash) {
|
|
64
67
|
assert(!hrefHash.startsWith('#'));
|
|
65
68
|
if (isLinkOnSamePage) {
|
|
66
|
-
var linkDataPageSection = findLinkData("#".concat(hrefHash), pageContext);
|
|
69
|
+
var linkDataPageSection = findLinkData("#".concat(hrefHash), { pageContext: pageContext, noWarning: noWarning });
|
|
67
70
|
if (!linkDataPageSection)
|
|
68
71
|
return null;
|
|
69
72
|
sectionTitle = parseMarkdownMini(linkDataPageSection.title);
|
|
@@ -85,7 +88,8 @@ function getLinkTextData(href, pageContext, doNotInferSectionTitle) {
|
|
|
85
88
|
}
|
|
86
89
|
return { linkData: linkData, sectionTitle: sectionTitle, isLinkOnSamePage: isLinkOnSamePage };
|
|
87
90
|
}
|
|
88
|
-
function findLinkData(href,
|
|
91
|
+
function findLinkData(href, _a) {
|
|
92
|
+
var pageContext = _a.pageContext, noWarning = _a.noWarning;
|
|
89
93
|
assert(href.startsWith('/') || href.startsWith('#'));
|
|
90
94
|
var linksAll = pageContext.linksAll;
|
|
91
95
|
var linkData = linksAll.find(function (_a) {
|
|
@@ -93,22 +97,26 @@ function findLinkData(href, pageContext) {
|
|
|
93
97
|
return href === url;
|
|
94
98
|
});
|
|
95
99
|
if (href.startsWith('#')) {
|
|
96
|
-
|
|
100
|
+
if (!noWarning) {
|
|
101
|
+
assertWarning(linkData, "Couldn't find ".concat(href, " in ").concat(pageContext.urlPathname, ", does it exist?"));
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
else {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
if (!noWarning) {
|
|
106
|
+
assertWarning(linkData, [
|
|
107
|
+
"Couldn't find page with URL ".concat(pc.bold(href)),
|
|
108
|
+
"\u2014 did you define it in",
|
|
109
|
+
[
|
|
110
|
+
pc.cyan('docpress.config.js'),
|
|
111
|
+
pc.dim('#{'),
|
|
112
|
+
pc.cyan('headings'),
|
|
113
|
+
pc.dim(','),
|
|
114
|
+
pc.cyan('headingsDetached'),
|
|
115
|
+
pc.dim('}'),
|
|
116
|
+
'?',
|
|
117
|
+
].join(''),
|
|
118
|
+
].join(' '));
|
|
119
|
+
}
|
|
112
120
|
}
|
|
113
121
|
return linkData !== null && linkData !== void 0 ? linkData : null;
|
|
114
122
|
}
|
|
@@ -21,6 +21,14 @@ function DocSearchInstall() {
|
|
|
21
21
|
searchParameters={{
|
|
22
22
|
filters: 'is_available:true',
|
|
23
23
|
}}
|
|
24
|
+
transformItems={(hits) => {
|
|
25
|
+
hits.map((hit) => {
|
|
26
|
+
if (hit.type === 'lvl1') {
|
|
27
|
+
hit.url = hit.url.split('#')[0]
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
return hits
|
|
31
|
+
}}
|
|
24
32
|
/>
|
|
25
33
|
</div>
|
|
26
34
|
)
|