Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for base tag #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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