@@ 9,7 9,7 @@
*
*/
-import { Component, ComponentChildren, JSX, h, toChildArray } from "preact";
+import { Component, ComponentChild, ComponentChildren, JSX, h, toChildArray } from "preact";
let refs: Helmet[] = [];
@@ 41,19 41,23 @@ const Wrapper = (props: {children: ComponentChildren}) => {
return null
}
+interface MetaItem {
+ name?: string;
+ property?: string;
+ content?: string;
+ httpEquiv?: string;
+ noScriptOnly?: boolean;
+}
+
interface HelmetProps {
title?: string;
titleTemplate?: string;
fallbackTitle?: string;
- meta?: Array<{
- name: string;
- property?: string;
- content?: string;
- }>;
+ meta?: MetaItem[];
}
export default class Helmet extends Component<HelmetProps, {}> {
- public static renderContent(props: HelmetProps): JSX.Element[] {
+ public static renderContent(props: HelmetProps): ComponentChild[] {
return [
<title data-helmet='true' key="title">{Helmet._getTitle(props)}</title>,
...Helmet._getMeta(props),
@@ 65,16 69,28 @@ export default class Helmet extends Component<HelmetProps, {}> {
return (!title && fallbackTitle) ? fallbackTitle : titleTemplate.replace('%s', title || '');
}
- private static _getMeta({meta = []}: {meta?: HelmetProps["meta"]}): JSX.Element[] {
- return meta.map(({ name, property, content }) =>
- <meta
- key={name}
- name={name}
- property={property}
- content={content}
- data-helmet
- />
- )
+ private static _getMeta({meta = []}: {meta?: HelmetProps["meta"]}): ComponentChild[] {
+ const noScriptOnlyItems = meta.filter(item => item.noScriptOnly);
+
+ const result = [
+ ...meta.filter(item => !item.noScriptOnly).map(Helmet._renderMetaItem),
+ noScriptOnlyItems.length > 0 &&
+ <noscript>
+ {noScriptOnlyItems.map(Helmet._renderMetaItem)}
+ </noscript>
+ ];
+
+ return result;
+ }
+
+ private static _renderMetaItem(meta: MetaItem): JSX.Element {
+ return <meta
+ name={meta.name}
+ property={meta.property}
+ content={meta.content}
+ http-equiv={meta.httpEquiv}
+ data-helmet
+ />;
}
constructor() {
@@ 217,7 217,10 @@ class BracketView extends Component<BracketViewProps, BracketViewState> {
sections.sort();
return <div>
- <Helmet title={bracket.name} />
+ <Helmet
+ title={bracket.name}
+ meta={[{httpEquiv: "refresh", content: "5", noScriptOnly: true}]}
+ />
<div>
<div class="bracketHeader">
<div>