diff --git a/hyperglass/models/config/web.py b/hyperglass/models/config/web.py index 29bdaff..4704f00 100644 --- a/hyperglass/models/config/web.py +++ b/hyperglass/models/config/web.py @@ -36,31 +36,6 @@ Side = constr(regex=r"left|right") LocationDisplayMode = t.Literal["auto", "dropdown", "gallery"] -class Analytics(HyperglassModel): - """Validation model for Google Analytics.""" - - enable: StrictBool = False - id: t.Optional[StrictStr] - - @validator("id") - def validate_id(cls, value, values): - """Ensure ID is set if analytics is enabled. - - Arguments: - value {str|None} -- Google Analytics ID - values {[type]} -- Already-validated model parameters - - Raises: - ValueError: Raised if analytics is enabled but no ID is set. - - Returns: - {str|None} -- Google Analytics ID if enabled. - """ - if values["enable"] and value is None: - raise ValueError("Analytics is enabled, but no ID is set.") - return value - - class Credit(HyperglassModel): """Validation model for developer credit.""" @@ -270,6 +245,8 @@ class Web(HyperglassModel): text: Text = Text() theme: Theme = Theme() location_display_mode: LocationDisplayMode = "auto" + custom_javascript: t.Optional[FilePath] + custom_html: t.Optional[FilePath] class WebPublic(Web): diff --git a/hyperglass/ui/.eslintignore b/hyperglass/ui/.eslintignore index 4c7afc3..e06f250 100644 --- a/hyperglass/ui/.eslintignore +++ b/hyperglass/ui/.eslintignore @@ -2,3 +2,4 @@ node_modules dist .next/ favicon-formats.ts +custom.*[js, html] diff --git a/hyperglass/ui/.gitignore b/hyperglass/ui/.gitignore index 4a9306a..3e347d9 100644 --- a/hyperglass/ui/.gitignore +++ b/hyperglass/ui/.gitignore @@ -1,5 +1,6 @@ .DS_Store .env* +custom.*[js, html] *.tsbuildinfo # dev/test files TODO.txt diff --git a/hyperglass/ui/.prettierignore b/hyperglass/ui/.prettierignore index 6b48447..fc2cfe7 100644 --- a/hyperglass/ui/.prettierignore +++ b/hyperglass/ui/.prettierignore @@ -7,3 +7,4 @@ package-lock.json tsconfig.json .next/ favicon-formats.ts +custom.*[js, html] diff --git a/hyperglass/ui/components/custom.tsx b/hyperglass/ui/components/custom.tsx new file mode 100644 index 0000000..e012d54 --- /dev/null +++ b/hyperglass/ui/components/custom.tsx @@ -0,0 +1,25 @@ +/** + * Render a generic script tag in the `` that contains any custom-defined Javascript, if + * defined. It no custom JS is defined, an empty fragment is rendered, which will not appear in + * the DOM. + */ +export const CustomJavascript = (props: React.PropsWithChildren): JSX.Element => { + const { children } = props; + if (typeof children === 'string' && children !== '') { + return