~vpzom/bracketmonster

74e01419fb53a312e73e7397f13c76482895a094 — Colin Reeder 4 years ago e015384 more-ssr
Add refresh tag for noscript on bracket
2 files changed, 37 insertions(+), 18 deletions(-)

M rosebush/src/client/Helmet.tsx
M rosebush/src/client/pages/bracket.tsx
M rosebush/src/client/Helmet.tsx => rosebush/src/client/Helmet.tsx +33 -17
@@ 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() {

M rosebush/src/client/pages/bracket.tsx => rosebush/src/client/pages/bracket.tsx +4 -1
@@ 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>