Skip to content

Commit

Permalink
fix: unexpect html string custom head children is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Oct 9, 2022
1 parent 3cad62c commit fabc4c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ class SSGBuilder {
const attrString = Object.keys(attrs).reduce((pre, cur) => {
return `${pre} ${cur}="${attrs[cur]}"`;
}, '');
return `<${tag} ${attrString}> ${children} </${tag}>`;
if (children === undefined || children === null) {
return `<${tag} ${attrString} />`;
} else {
return `<${tag} ${attrString}>${children}</${tag}>`;
}
})
.join('\n');

Expand All @@ -258,10 +262,10 @@ class SSGBuilder {
this.#config.siteData!.icon
}" type="image/svg+xml"></link>
${headTag || ''}
${helmet?.title.toString() || ''}
${helmet?.meta.toString() || ''}
${helmet?.link.toString() || ''}
${helmet?.style.toString() || ''}
${helmet?.title?.toString() || ''}
${helmet?.meta?.toString() || ''}
${helmet?.link?.toString() || ''}
${helmet?.style?.toString() || ''}
<script defer src='https://ga.jspm.io/npm:es-module-shims@1.6.0/dist/es-module-shims.js'></script>
<script type="importmap">
{
Expand Down
19 changes: 13 additions & 6 deletions src/theme-default/layout/DocLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ import { Content, usePageData } from 'island/client';
import { useLocaleSiteData } from '../../logic';

export function DocLayout() {
const { toc: headers = [], siteData, pagePath } = usePageData();
const { toc: headers = [], siteData, pagePath, frontmatter } = usePageData();
const themeConfig = siteData.themeConfig;
const localesData = useLocaleSiteData();
const sidebar = localesData.sidebar || [];
// siderbar Priority
// 1. frontmatter.sidebar
// 2. themeConfig.locales.sidebar
// 3. themeConfig.sidebar
const hasSidebar =
(Array.isArray(sidebar) && sidebar.length > 0) ||
Object.keys(sidebar).length > 0;
frontmatter?.sidebar !== false &&
((Array.isArray(sidebar) && sidebar.length > 0) ||
Object.keys(sidebar).length > 0);
const outlineTitle =
localesData?.outlineTitle || themeConfig?.outlineTitle || 'ON THIS PAGE';

const hasAside = headers.length > 0 && themeConfig.outline !== false;
const hasAside =
headers.length > 0 &&
themeConfig.outline !== false &&
frontmatter?.outline !== false;

return (
<div p="t-0 x-6 b-24 sm:6">
Expand All @@ -27,7 +34,7 @@ export function DocLayout() {
<div
relative="~"
m="x-auto"
className="md:max-w-712px lg:min-w-640px"
className={'md:max-w-712px lg:min-w-640px'}
>
<div className="island-doc">
<Content fallback={<div>Loading...</div>} />
Expand Down

1 comment on commit fabc4c1

@vercel
Copy link

@vercel vercel bot commented on fabc4c1 Oct 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.