diff options
author | Sébastien Rochette <statnmap@users.noreply.github.com> | 2018-01-31 03:44:19 +0300 |
---|---|---|
committer | Patrick Collins <thepatrickcollins@gmail.com> | 2018-01-31 03:44:19 +0300 |
commit | d59f56ac6682b3ed690e67cffdc755141986efd1 (patch) | |
tree | 3158cccfc277bfd314a6885d7d8c960fa6150542 | |
parent | 87c4a678c12260054ca2b2107c676022c6a6089e (diff) |
Add Syntax highlighting for blogs with embed code (#108)
* Add gitignore
* Delete .gitignore
* Add highlightjs for code syntax highlighting
-rw-r--r-- | exampleSite/config.toml | 7 | ||||
-rw-r--r-- | layouts/partials/footer.html | 12 | ||||
-rw-r--r-- | layouts/partials/header.html | 7 |
3 files changed, 26 insertions, 0 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 394f8c9..ff3528c 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -45,6 +45,13 @@ pluralizeListTitles = false customCSS = ["default"] customJS = ["default"] + # options for highlight.js (version, additional languages, and theme) + disable_highlight = false # set to true to disable Highlight + highlightjsVersion = "9.11.0" + highlightjsCDN = "//cdn.bootcss.com" + highlightjsLang = ["r", "yaml", "css"] + highlightjsTheme = "github" + # Disqus will take priority over Staticman (github.com/eduardoboucas/staticman) # due to its ease of use. Feel free to check out both and decide what you would # prefer to use. See Staticman.yml for additional settings. diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 7d1686c..cd3c030 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -8,6 +8,18 @@ {{ $.Scratch.Set "jsFiles" false }} {{ end }} + {{ if (not .Params.disable_highlight) }} + {{ $highVer := .Site.Params.highlightjsVersion }} + {{ $highCDN := (.Site.Params.highlightjsCDN | default "//cdn.bootcss.com") }} + {{ if (not (eq $highVer "")) }} + <script src="{{ $highCDN }}/highlight.js/{{ $highVer }}/highlight.min.js"></script> + {{ $.Scratch.Set "highLangs" .Site.Params.highlightjsLang }} + {{ range .Params.highlightjsLang }}{{ $.Scratch.Add "highLangs" . }}{{ end }} + {{ range ($.Scratch.Get "highLangs") }} + <script src="{{ $highCDN }}/highlight.js/{{ $highVer }}/languages/{{ . }}.min.js"></script>{{ end }} + <script>hljs.configure({languages: []}); hljs.initHighlightingOnLoad();</script> + {{ end }} + {{ end }} <!-- If the value "default" is passed into the param then we will first load the standard js files associated with the theme --> {{ if or (in ($.Scratch.Get "jsFiles") "default") (eq ($.Scratch.Get "jsFiles") false) }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index cf53dcc..e834f0a 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -63,6 +63,13 @@ {{ end }} {{ end }} +{{ if (not .Params.disable_highlight) }} + {{ $highTheme := .Site.Params.highlightjsTheme }} + {{ with .Site.Params.highlightjsVersion }} + <link href='{{ $.Site.Params.highlightjsCDN | default "//cdn.bootcss.com" }}/highlight.js/{{ . }}/styles/{{ $highTheme }}.min.css' rel='stylesheet' type='text/css' /> + {{ end }} +{{ end }} + {{ template "_internal/google_analytics.html" . }} </head> <body> |