Skip to content

Commit

Permalink
use handlebars if statements in templating
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjvs committed Jul 23, 2023
1 parent 386afd2 commit 7d6d41f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
9 changes: 6 additions & 3 deletions example.env
Original file line number Diff line number Diff line change
@@ -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
40 changes: 21 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@

<title>movie-web</title>

<!-- OpenSearch -->
{{{ opensearch }}}

<!-- Google Sitelinks -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "https://movie-web.app/",
"potentialAction": {
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://movie-web.app/browse/{search_term_string}"
},
"query-input": "required name=search_term_string"
}
}
</script>
{{#if opensearchEnabled }}
<!-- 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": "{{ routeDomain }}",
"potentialAction": {
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"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>
Expand Down
2 changes: 1 addition & 1 deletion src/assets/opensearch.xml.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
6 changes: 4 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 7d6d41f

Please sign in to comment.