@brillout/docpress 0.14.0 → 0.15.1

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/ExternalLinks.tsx CHANGED
@@ -12,7 +12,7 @@ import '@docsearch/css'
12
12
 
13
13
  function ExternalLinks(props: { style?: React.CSSProperties }) {
14
14
  const pageContext = usePageContext()
15
- const { projectInfo, i18n } = pageContext.globalContext.config.docpress
15
+ const { github, discord, bluesky, i18n, twitter } = pageContext.globalContext.config.docpress
16
16
  const iconI18n = !i18n ? null : (
17
17
  <LinkIcon
18
18
  className="decolorize-4"
@@ -31,18 +31,10 @@ function ExternalLinks(props: { style?: React.CSSProperties }) {
31
31
  }}
32
32
  >
33
33
  {iconI18n}
34
- {projectInfo.discordInvite && (
35
- <LinkIcon className="decolorize-6" icon={iconDiscord} href={projectInfo.discordInvite} />
36
- )}
37
- <LinkIcon className="decolorize-4" icon={iconTwitter} href={projectInfo.twitterProfile} />
38
- {projectInfo.blueskyHandle && (
39
- <LinkIcon
40
- className="decolorize-6"
41
- icon={iconBluesky}
42
- href={`https://bsky.app/profile/${projectInfo.blueskyHandle}`}
43
- />
44
- )}
45
- <LinkIcon className="decolorize-4" icon={iconGithub} href={projectInfo.githubRepository} />
34
+ {discord && <LinkIcon className="decolorize-6" icon={iconDiscord} href={discord} />}
35
+ {twitter && <LinkIcon className="decolorize-4" icon={iconTwitter} href={`https://x.com/${twitter.slice(1)}`} />}
36
+ {bluesky && <LinkIcon className="decolorize-6" icon={iconBluesky} href={`https://bsky.app/profile/${bluesky}`} />}
37
+ <LinkIcon className="decolorize-4" icon={iconGithub} href={github} />
46
38
  <ChangelogButton />
47
39
  </div>
48
40
  )
@@ -50,10 +42,10 @@ function ExternalLinks(props: { style?: React.CSSProperties }) {
50
42
 
51
43
  function ChangelogButton() {
52
44
  const pageContext = usePageContext()
53
- const { projectInfo } = pageContext.globalContext.config.docpress
45
+ const { version, github } = pageContext.globalContext.config.docpress
54
46
  return (
55
47
  <a
56
- href={`${projectInfo.githubRepository}/blob/main/CHANGELOG.md`}
48
+ href={`${github}/blob/main/CHANGELOG.md`}
57
49
  className="colorize-on-hover"
58
50
  style={{
59
51
  display: 'flex',
@@ -72,7 +64,7 @@ function ChangelogButton() {
72
64
  }}
73
65
  >
74
66
  <span id="version-number" className="decolorize-7">
75
- v{projectInfo.projectVersion}
67
+ v{version}
76
68
  </span>
77
69
  <img className="decolorize-6" src={iconChangelog} height={16} style={{ marginLeft: 6 }} />
78
70
  </div>
package/Layout.tsx CHANGED
@@ -18,7 +18,6 @@ import { autoScrollNav_SSR } from './autoScrollNav'
18
18
  import { SearchLink } from './docsearch/SearchLink'
19
19
  import { navigate } from 'vike/client/router'
20
20
  import { css } from './utils/css'
21
- import { PassThrough } from './utils/PassTrough'
22
21
  import { Style } from './utils/Style'
23
22
  import { cls } from './utils/cls'
24
23
  import { iconBooks } from './icons'
@@ -282,10 +281,7 @@ const menuLinkStyle: React.CSSProperties = {
282
281
  function NavHead({ isNavLeft }: { isNavLeft?: true }) {
283
282
  const pageContext = usePageContext()
284
283
  const { isLandingPage } = pageContext.conf
285
- const {
286
- navMaxWidth,
287
- projectInfo: { projectName },
288
- } = pageContext.globalContext.config.docpress
284
+ const { navMaxWidth, name, algolia } = pageContext.globalContext.config.docpress
289
285
 
290
286
  const navSecondaryContent = (
291
287
  <div
@@ -345,7 +341,7 @@ function NavHead({ isNavLeft }: { isNavLeft?: true }) {
345
341
  maxWidth: navMaxWidth,
346
342
  margin: 'auto',
347
343
  height: 'var(--nav-head-height)',
348
- fontSize: `min(15.2px, ${isProjectNameShort(projectName) ? '4.8cqw' : '4.5cqw'})`,
344
+ fontSize: `min(15.2px, ${isProjectNameShort(name) ? '4.8cqw' : '4.5cqw'})`,
349
345
  color: '#666',
350
346
  ['--icon-text-padding']: 'min(8px, 1.8cqw)',
351
347
  display: 'flex',
@@ -354,7 +350,7 @@ function NavHead({ isNavLeft }: { isNavLeft?: true }) {
354
350
  >
355
351
  <NavLogo className="grow-half" />
356
352
  {!isNavLeft && <div className="desktop-grow" />}
357
- <SearchLink className="grow-half" style={menuLinkStyle} />
353
+ {algolia && <SearchLink className="grow-half" style={menuLinkStyle} />}
358
354
  <MenuToggleMain className="grow-full" style={menuLinkStyle} />
359
355
  {navSecondaryContent}
360
356
  </div>
@@ -487,7 +483,7 @@ function NavHeaderLeftFullWidthBackground() {
487
483
  function NavLogo({ className }: { className: string }) {
488
484
  const pageContext = usePageContext()
489
485
  const iconSize = pageContext.globalContext.config.docpress.navLogoSize ?? 39
490
- const { projectName } = pageContext.globalContext.config.docpress.projectInfo
486
+ const { name } = pageContext.globalContext.config.docpress
491
487
  return (
492
488
  <a
493
489
  className={cls(['nav-logo', className])}
@@ -500,7 +496,7 @@ function NavLogo({ className }: { className: string }) {
500
496
  href="/"
501
497
  >
502
498
  <img
503
- src={pageContext.globalContext.config.docpress.logoUrl}
499
+ src={pageContext.globalContext.config.docpress.logo}
504
500
  style={{
505
501
  height: iconSize,
506
502
  width: iconSize,
@@ -516,17 +512,17 @@ function NavLogo({ className }: { className: string }) {
516
512
  <span
517
513
  style={{
518
514
  marginLeft: `calc(var(--icon-text-padding) + 2px)`,
519
- fontSize: isProjectNameShort(projectName) ? '1.65em' : '1.3em',
515
+ fontSize: isProjectNameShort(name) ? '1.65em' : '1.3em',
520
516
  ...pageContext.globalContext.config.docpress.navLogoTextStyle,
521
517
  }}
522
518
  >
523
- {projectName}
519
+ {name}
524
520
  </span>
525
521
  </a>
526
522
  )
527
523
  }
528
- function isProjectNameShort(projectName: string) {
529
- return projectName.length <= 4
524
+ function isProjectNameShort(name: string) {
525
+ return name.length <= 4
530
526
  }
531
527
 
532
528
  let onMouseIgnore: ReturnType<typeof setTimeout> | undefined
@@ -24,9 +24,8 @@ function getRepoHref(path: string, editMode = false) {
24
24
  path = '/' + path
25
25
  }
26
26
  const viewMode = path.endsWith('/') && !editMode ? 'tree' : 'blob'
27
- const { githubRepository } = pageContext.globalContext.config.docpress.projectInfo
28
- assert(githubRepository.startsWith('https://github.com/'))
29
- let href = `${githubRepository}/${viewMode}/main${path}`
27
+ const { github } = pageContext.globalContext.config.docpress
28
+ let href = `${github}/${viewMode}/main${path}`
30
29
  if (editMode) href += '?plain=1'
31
30
  return href
32
31
  }
@@ -22,9 +22,8 @@ function getRepoHref(path, editMode) {
22
22
  path = '/' + path;
23
23
  }
24
24
  var viewMode = path.endsWith('/') && !editMode ? 'tree' : 'blob';
25
- var githubRepository = pageContext.globalContext.config.docpress.projectInfo.githubRepository;
26
- assert(githubRepository.startsWith('https://github.com/'));
27
- var href = "".concat(githubRepository, "/").concat(viewMode, "/main").concat(path);
25
+ var github = pageContext.globalContext.config.docpress.github;
26
+ var href = "".concat(github, "/").concat(viewMode, "/main").concat(path);
28
27
  if (editMode)
29
28
  href += '?plain=1';
30
29
  return href;
@@ -114,7 +114,7 @@ function getTitles(activeHeading, urlPathname, config) {
114
114
  var pageTitle = isLandingPage ? null : title;
115
115
  var documentTitle = activeHeading.titleDocument || jsxToTextContent(parseMarkdownMini(title));
116
116
  if (!isLandingPage) {
117
- documentTitle += ' | ' + config.projectInfo.projectName;
117
+ documentTitle += ' | ' + config.name;
118
118
  }
119
119
  if (isLandingPage) {
120
120
  pageTitle = null;
@@ -1,37 +1,31 @@
1
1
  export type { Config };
2
2
  import type { HeadingDefinition, HeadingDetachedDefinition } from './Heading';
3
3
  type Config = {
4
- projectInfo: {
5
- githubRepository: string;
6
- githubIssues: string;
7
- githubDiscussions?: string;
8
- projectName: string;
9
- projectVersion: string;
10
- discordInvite?: string;
11
- twitterProfile: string;
12
- blueskyHandle?: string;
13
- };
14
- docsDir?: string;
15
- logoUrl?: string;
16
- faviconUrl?: string;
17
- algolia: null | {
4
+ name: string;
5
+ version: string;
6
+ url: string;
7
+ /** Sets `<meta name="description" content="${tagline}" />` */
8
+ tagline: string;
9
+ logo: string;
10
+ favicon?: string;
11
+ banner?: string;
12
+ github: string;
13
+ discord?: string;
14
+ twitter?: string;
15
+ bluesky?: string;
16
+ headings: HeadingDefinition[];
17
+ headingsDetached: HeadingDetachedDefinition[];
18
+ categories?: Category[];
19
+ algolia?: {
18
20
  appId: string;
19
21
  apiKey: string;
20
22
  indexName: string;
21
23
  };
22
- headings: HeadingDefinition[];
23
- headingsDetached: HeadingDetachedDefinition[];
24
- categories?: Category[];
25
- /** Sets `<meta name="description" content="${tagline}" />` */
26
- tagline: string;
27
- websiteUrl: string;
28
- bannerUrl?: string;
29
- twitterHandle: string;
30
- globalNote?: React.ReactNode;
31
- topNavigation?: React.ReactNode;
32
24
  i18n?: true;
33
25
  pressKit?: true;
34
- sponsorGithubAccount?: string;
26
+ docsDir?: string;
27
+ topNavigation?: React.ReactNode;
28
+ globalNote?: React.ReactNode;
35
29
  navMaxWidth?: number;
36
30
  navLogoSize?: number;
37
31
  navLogoStyle?: React.CSSProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
@@ -2,9 +2,10 @@ export { onRenderHtml }
2
2
 
3
3
  import ReactDOMServer from 'react-dom/server'
4
4
  import { escapeInject, dangerouslySkipEscape } from 'vike/server'
5
- import { assert } from '../utils/server'
5
+ import { assert, assertUsage } from '../utils/server'
6
6
  import { getPageElement } from './getPageElement'
7
7
  import type { PageContextServer } from 'vike/types'
8
+ import type { Config } from '../types/Config'
8
9
 
9
10
  async function onRenderHtml(pageContext: PageContextServer): Promise<any> {
10
11
  const page = getPageElement(pageContext)
@@ -17,8 +18,7 @@ async function onRenderHtml(pageContext: PageContextServer): Promise<any> {
17
18
 
18
19
  const pageHtml = ReactDOMServer.renderToString(page)
19
20
 
20
- const faviconUrl =
21
- pageContext.globalContext.config.docpress.faviconUrl ?? pageContext.globalContext.config.docpress.logoUrl
21
+ const faviconUrl = pageContext.globalContext.config.docpress.favicon ?? pageContext.globalContext.config.docpress.logo
22
22
  assert(faviconUrl)
23
23
 
24
24
  const { documentTitle } = pageContext.conf
@@ -72,24 +72,21 @@ function getActiveCategory(pageContext: PageContextServer) {
72
72
  return activeCategory
73
73
  }
74
74
 
75
- function getOpenGraphTags(
76
- url: string,
77
- documentTitle: string,
78
- meta: { tagline: string; websiteUrl: string; twitterHandle: string; bannerUrl?: string },
79
- ) {
80
- const { tagline, websiteUrl, twitterHandle, bannerUrl } = meta
75
+ function getOpenGraphTags(url: string, documentTitle: string, config: Config) {
76
+ const { tagline, url: websiteUrl, twitter, banner } = config
81
77
  assert(url.startsWith('/'))
78
+ assertUsage(!twitter || twitter.startsWith('@'), `twitter handle must start with @`)
82
79
 
83
- const metaBanner = !bannerUrl
80
+ const metaBanner = !banner
84
81
  ? ''
85
82
  : escapeInject`
86
- <meta property="og:image" content="${bannerUrl}">
83
+ <meta property="og:image" content="${banner}">
87
84
  <meta name="twitter:card" content="summary_large_image">
88
85
  `
89
- const metaTwitter = !twitterHandle
86
+ const metaTwitter = !twitter
90
87
  ? ''
91
88
  : escapeInject`
92
- <meta name="twitter:site" content="${twitterHandle}">
89
+ <meta name="twitter:site" content="${twitter}">
93
90
  `
94
91
  // See view-source:https://vitejs.dev/
95
92
  return escapeInject`
package/resolveConf.ts CHANGED
@@ -133,7 +133,7 @@ function getTitles(activeHeading: HeadingResolved | HeadingDetachedResolved, url
133
133
  let documentTitle = activeHeading.titleDocument || jsxToTextContent(parseMarkdownMini(title))
134
134
 
135
135
  if (!isLandingPage) {
136
- documentTitle += ' | ' + config.projectInfo.projectName
136
+ documentTitle += ' | ' + config.name
137
137
  }
138
138
 
139
139
  if (isLandingPage) {
package/types/Config.ts CHANGED
@@ -3,37 +3,36 @@ export type { Config }
3
3
  import type { HeadingDefinition, HeadingDetachedDefinition } from './Heading'
4
4
 
5
5
  type Config = {
6
- projectInfo: {
7
- githubRepository: string
8
- githubIssues: string
9
- githubDiscussions?: string
10
- projectName: string
11
- projectVersion: string
12
- discordInvite?: string
13
- twitterProfile: string
14
- blueskyHandle?: string
15
- }
16
- docsDir?: string
17
- logoUrl?: string
18
- faviconUrl?: string
19
- algolia: null | {
6
+ name: string
7
+ version: string
8
+ url: string
9
+ /** Sets `<meta name="description" content="${tagline}" />` */
10
+ tagline: string
11
+ logo: string
12
+ favicon?: string
13
+ banner?: string
14
+
15
+ github: string
16
+ discord?: string
17
+ twitter?: string
18
+ bluesky?: string
19
+
20
+ headings: HeadingDefinition[]
21
+ headingsDetached: HeadingDetachedDefinition[]
22
+ categories?: Category[]
23
+
24
+ algolia?: {
20
25
  appId: string
21
26
  apiKey: string
22
27
  indexName: string
23
28
  }
24
- headings: HeadingDefinition[]
25
- headingsDetached: HeadingDetachedDefinition[]
26
- categories?: Category[]
27
- /** Sets `<meta name="description" content="${tagline}" />` */
28
- tagline: string
29
- websiteUrl: string
30
- bannerUrl?: string
31
- twitterHandle: string
32
- globalNote?: React.ReactNode
33
- topNavigation?: React.ReactNode
29
+
34
30
  i18n?: true
35
31
  pressKit?: true
36
- sponsorGithubAccount?: string
32
+ docsDir?: string
33
+
34
+ topNavigation?: React.ReactNode
35
+ globalNote?: React.ReactNode
37
36
  navMaxWidth?: number
38
37
  navLogoSize?: number
39
38
  navLogoStyle?: React.CSSProperties