mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-02 06:58:06 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 11ef360467 | |||
| 30e9e18ab4 | |||
| fcae8b0bf3 | |||
| a47fb6c2bd | |||
| d86eb47bf7 |
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix invalid HTML on an Announcement banner without a CTA.
|
||||||
@@ -104,6 +104,7 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
|
|||||||
const resolve = ADAPTIVE_CONTENT_HOSTS.includes(siteRequestURL.hostname)
|
const resolve = ADAPTIVE_CONTENT_HOSTS.includes(siteRequestURL.hostname)
|
||||||
? resolvePublishedContentByUrl
|
? resolvePublishedContentByUrl
|
||||||
: getPublishedContentByURL;
|
: getPublishedContentByURL;
|
||||||
|
|
||||||
const siteURLData = await throwIfDataError(
|
const siteURLData = await throwIfDataError(
|
||||||
resolve({
|
resolve({
|
||||||
url: siteRequestURL.toString(),
|
url: siteRequestURL.toString(),
|
||||||
@@ -290,7 +291,7 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
|
|||||||
return writeResponseCookies(response, cookies);
|
return writeResponseCookies(response, cookies);
|
||||||
};
|
};
|
||||||
|
|
||||||
// For https://preview/<siteURL> requests,
|
// For https://preview/<siteId> requests,
|
||||||
if (siteRequestURL.hostname === 'preview') {
|
if (siteRequestURL.hostname === 'preview') {
|
||||||
return serveWithQueryAPIToken(
|
return serveWithQueryAPIToken(
|
||||||
// We scope the API token to the site ID.
|
// We scope the API token to the site ID.
|
||||||
|
|||||||
@@ -18,35 +18,18 @@ export function AnnouncementBanner(props: {
|
|||||||
}) {
|
}) {
|
||||||
const { announcement, contentRef } = props;
|
const { announcement, contentRef } = props;
|
||||||
|
|
||||||
const hasLink = announcement.link && contentRef?.href;
|
const hasLink = contentRef?.href;
|
||||||
const closeable = announcement.style !== 'danger';
|
const closeable = announcement.style !== 'danger';
|
||||||
|
|
||||||
const Tag = hasLink ? Link : 'div';
|
|
||||||
const style = BANNER_STYLES[announcement.style];
|
const style = BANNER_STYLES[announcement.style];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="announcement-banner" className="theme-bold:bg-header-background pt-4 pb-2">
|
<div id="announcement-banner" className="theme-bold:bg-header-background pt-4 pb-2">
|
||||||
<div className="scroll-nojump">
|
<div className="scroll-nojump">
|
||||||
<div className={tcls('relative', CONTAINER_STYLE)}>
|
<div className={tcls('relative', CONTAINER_STYLE)}>
|
||||||
<Tag
|
<AnnouncementBannerParent
|
||||||
href={contentRef?.href ?? ''}
|
announcement={announcement}
|
||||||
className={tcls(
|
closeable={closeable}
|
||||||
'flex w-full items-start justify-center overflow-hidden rounded-md straight-corners:rounded-none px-4 py-3 text-neutral-strong text-sm theme-bold:ring-1 theme-gradient:ring-1 ring-inset transition-colors',
|
contentRef={contentRef}
|
||||||
style.container,
|
|
||||||
closeable && 'pr-12',
|
|
||||||
hasLink && style.hover
|
|
||||||
)}
|
|
||||||
insights={
|
|
||||||
announcement.link
|
|
||||||
? {
|
|
||||||
type: 'link_click',
|
|
||||||
link: {
|
|
||||||
target: announcement.link.to,
|
|
||||||
position: SiteInsightsLinkPosition.Announcement,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
icon={style.icon as IconName}
|
icon={style.icon as IconName}
|
||||||
@@ -75,7 +58,7 @@ export function AnnouncementBanner(props: {
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</Tag>
|
</AnnouncementBannerParent>
|
||||||
{closeable ? (
|
{closeable ? (
|
||||||
<button
|
<button
|
||||||
className={`absolute top-0 right-4 mt-2 mr-2 rounded straight-corners:rounded-none p-1.5 transition-all hover:ring-1 sm:right-6 md:right-8 ${style.close}`}
|
className={`absolute top-0 right-4 mt-2 mr-2 rounded straight-corners:rounded-none p-1.5 transition-all hover:ring-1 sm:right-6 md:right-8 ${style.close}`}
|
||||||
@@ -91,6 +74,48 @@ export function AnnouncementBanner(props: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the appropriate parent for the announcement banner depending on the presence of a link.
|
||||||
|
*/
|
||||||
|
function AnnouncementBannerParent(props: {
|
||||||
|
announcement: CustomizationAnnouncement;
|
||||||
|
children: React.ReactNode;
|
||||||
|
closeable: boolean;
|
||||||
|
contentRef: ResolvedContentRef | null;
|
||||||
|
}) {
|
||||||
|
const { announcement, contentRef, closeable, children } = props;
|
||||||
|
const style = BANNER_STYLES[announcement.style];
|
||||||
|
|
||||||
|
const classNames = [
|
||||||
|
'flex w-full items-start justify-center overflow-hidden rounded-md straight-corners:rounded-none px-4 py-3 text-neutral-strong text-sm theme-bold:ring-1 theme-gradient:ring-1 ring-inset transition-colors',
|
||||||
|
style.container,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (contentRef?.href) {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
href={contentRef.href}
|
||||||
|
className={tcls(classNames, closeable && 'pr-12', style.hover)}
|
||||||
|
insights={
|
||||||
|
announcement.link
|
||||||
|
? {
|
||||||
|
type: 'link_click',
|
||||||
|
link: {
|
||||||
|
target: announcement.link.to,
|
||||||
|
position: SiteInsightsLinkPosition.Announcement,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div className={tcls(classNames)}>{children}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismiss the announcement banner and store the dismissal state in local storage.
|
* Dismiss the announcement banner and store the dismissal state in local storage.
|
||||||
* @see AnnouncementScript
|
* @see AnnouncementScript
|
||||||
|
|||||||
Reference in New Issue
Block a user