Skip to content

Commit

Permalink
default template as external file and update of HOWTO
Browse files Browse the repository at this point in the history
  • Loading branch information
kpym committed Oct 22, 2024
1 parent 8754227 commit 6cd570b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
10 changes: 6 additions & 4 deletions HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ All this theme are hosted on GitHub pages of the [markdown-css](https://github.c
The custom HTML template can contain the following variables:

- `{{.html}}` contains the parsed html code from the markdown;
- `{{.css}}` contains the css link obtained by the `--css` parameter;
- `{{.css}}` contains a list of css links or codes obtained from the `--css` parameter;
- `{{.title}}` contains the first `h1` title, or the `--title` parameter if no `h1` title is present in the code.

```shell
Expand All @@ -34,12 +34,14 @@ The custom HTML template can contain the following variables:
We can use a file or a string as `--html` parameter (run in bash here):

```shell
> echo "*test*" | gm -t "Test page" -c air --html $'title: {{.title}}\ncss: {{.css}}\nhtml: {{.html}}'
> echo "*test*" | gm -q -t "Test page" -c air --html $'title: {{.title}}\ncss: {{.css}}\nhtml: {{.html}}'
title: Test page
css: https://kpym.github.io/markdown-css/air.min.css
css: [{https://kpym.github.io/markdown-css/air.min.css }]
html: <p><em>test</em></p>
```

The default template is [gm_template.html](gm_template.html).

## Serve at localhost

When used with `--serve`/`-s` flag `gm` start serving all files from the specified folder. The `.md` files are converted and served as `html` but all other files are staticly served. To serve the current folder you can simply run:
Expand All @@ -64,7 +66,7 @@ Here is an example of possible `.gitlab-ci.yml`:
pages:
image: alpine
script:
- wget -c https://github.com/kpym/gm/releases/download/v0.18.3/gm_0.18.3_Linux_64bit.tar.gz -O - | tar -C /usr/local/bin -xz gm
- wget -c https://github.com/kpym/gm/releases/download/v0.20.0/gm_0.20.0_Linux_intel64.tar.gz -O - | tar -C /usr/local/bin -xz gm
- gm --pages '**/*'
artifacts:
paths:
Expand Down
30 changes: 3 additions & 27 deletions gm_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,9 @@ import (
)

// defaultHTMLTemplate is the default value for `html` flag
var defaultHTMLTemplate string = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{{- range .css }}
{{- with .Url }}
<link rel="stylesheet" type="text/css" href="{{.}}">
{{- end }}
{{- with .Code }}
{{.}}
{{- end }}
{{- end }}
{{- with .title }}
<title>{{.}}</title>
{{- end }}
</head>
<body>
<article class="markdown-body">
{{.html}}
</article>
{{- if .liveupdate }}
<script src="live.js#html,css"></script>
{{- end }}
</body>
</html>
`
//
//go:embed gm_template.html
var defaultHTMLTemplate string

// the favicon image for all served pages
//
Expand Down

0 comments on commit 6cd570b

Please sign in to comment.