Skip to content

Commit

Permalink
feat: add support for base tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Trümper committed Nov 18, 2023
1 parent fcbf45b commit 564dc00
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/reference/elm-land-json.md
Expand Up @@ -162,6 +162,7 @@ If you ever need to audit which variables are exposed to your frontend, this one
, meta : List (Dict String String)
, link : List (Dict String String)
, script : List (Dict String String)
, base : List (Dict String String)
}
```
:::
Expand All @@ -180,6 +181,7 @@ Here is the general shape of that HTML template to give you an overview:
{{ meta tags }}
{{ link tags }}
{{ script tags }}
{{ base tag }}
</head>
<body>
<!-- Elm Land's entrypoint -->
Expand Down Expand Up @@ -476,6 +478,52 @@ __Output__: `dist/index.html`

:::

### app.html.base

::: info TYPE
```elm
List (Dict String String)
```
:::

For each item in the list, an attribute will be rendered within the `<base>` tag.

::: tip EXAMPLE

__Input__: `elm-land.json`

```jsonc {7}
{
"app": {
// ...
"html": {
// ...
"base": [
{
"href": "https://href.example.elm.land" ,
"target": "fun"
}
]
}
}
}
```

__Output__: `dist/index.html`

```html {5}
<!DOCTYPE html>
<html>
<head>
<!-- ... -->
<base href="https://href.example.elm.land" target="fun">
</head>
<!-- ... -->
</html>
```

:::

## app.router

::: info TYPE
Expand Down
9 changes: 9 additions & 0 deletions projects/cli/src/effects.js
Expand Up @@ -564,7 +564,16 @@ const generateHtml = async (config) => {
let linkTags = toSelfClosingHtmlTags('link', attempt(_ => config.app.html.link))
let scriptTags = toHtmlTags('script', attempt(_ => config.app.html.script))

let baseTagsAttributes = toAttributeString(attempt(() => config.app.html.base ))
let baseTag = ''
if(baseTagsAttributes.length > 0){
baseTag = `<base${baseTagsAttributes}>`
}

let combinedTags = [...titleTags, ...metaTags, ...linkTags, ...scriptTags]
if(baseTag !== ''){
combinedTags.push(baseTag)
}
let headTags = combinedTags.length > 0
? '\n ' + combinedTags.join('\n ') + '\n '
: ''
Expand Down

0 comments on commit 564dc00

Please sign in to comment.