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

View File

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

View File

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