use handlebars if statements in templating

This commit is contained in:
mrjvs 2023-07-23 12:18:20 +02:00
parent 386afd21ea
commit 7d6d41fb48
4 changed files with 31 additions and 24 deletions

View file

@ -1,5 +1,8 @@
# make sure the cors proxy url does NOT have a slash at the end
VITE_CORS_PROXY_URL=...
VITE_TMDB_READ_API_KEY=...
VITE_OPENSEARCH_ENABLED=false
VITE_APP_DOMAIN="http://localhost:5173"
# make sure the cors proxy url does NOT have a slash at the end
VITE_CORS_PROXY_URL=...
# make sure the domain does NOT have a slash at the end
VITE_APP_DOMAIN=http://localhost:5173

View file

@ -34,25 +34,27 @@
<title>movie-web</title>
{{#if opensearchEnabled }}
<!-- OpenSearch -->
{{{ opensearch }}}
<link rel="search" type="application/opensearchdescription+xml" title="movie-web" href="/opensearch.xml">
<!-- Google Sitelinks -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "https://movie-web.app/",
"url": "{{ routeDomain }}",
"potentialAction": {
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://movie-web.app/browse/{search_term_string}"
"urlTemplate": "{{ routeDomain }}/browse/?q={search_term_string}"
},
"query-input": "required name=search_term_string"
}
}
</script>
{{/if}}
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>

View file

@ -2,5 +2,5 @@
<ShortName>movie-web</ShortName>
<Description>The place for your favorite movies &amp; shows</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" template="{{ appdomain }}/browse/{searchTerms}" />
<Url type="text/html" template="{{ routeDomain }}/browse/?q={searchTerms}" />
</OpenSearchDescription>

View file

@ -13,8 +13,10 @@ export default defineConfig(({ mode }) => {
plugins: [
handlebars({
vars: {
opensearch: env.VITE_OPENSEARCH_ENABLED ? '<link rel="search" type="application/opensearchdescription+xml" title="movie-web" href="src/assets/opensearch.xml">' : "",
appdomain: env.VITE_APP_DOMAIN,
opensearchEnabled: env.VITE_OPENSEARCH_ENABLED === "true",
routeDomain: env.VITE_APP_DOMAIN + (env.VITE_NORMAL_ROUTER !== 'true' ? "/#" : ""),
domain: env.VITE_APP_DOMAIN,
env,
},
}),
react({