Put the highlight logic into one common template
It now loads unconditionally and highlights all code blocks. TODO: optimize to not load when there are no blocks
This commit is contained in:
parent
03ac402c37
commit
a82882fddc
6 changed files with 27 additions and 49 deletions
|
@ -55,12 +55,14 @@ func initTemplate(name string) {
|
||||||
filepath.Join(templatesDir, name+".tmpl"),
|
filepath.Join(templatesDir, name+".tmpl"),
|
||||||
filepath.Join(templatesDir, "include", "posts.tmpl"),
|
filepath.Join(templatesDir, "include", "posts.tmpl"),
|
||||||
filepath.Join(templatesDir, "include", "footer.tmpl"),
|
filepath.Join(templatesDir, "include", "footer.tmpl"),
|
||||||
|
filepath.Join(templatesDir, "include", "render.tmpl"),
|
||||||
filepath.Join(templatesDir, "base.tmpl"),
|
filepath.Join(templatesDir, "base.tmpl"),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
|
templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
|
||||||
filepath.Join(templatesDir, name+".tmpl"),
|
filepath.Join(templatesDir, name+".tmpl"),
|
||||||
filepath.Join(templatesDir, "include", "footer.tmpl"),
|
filepath.Join(templatesDir, "include", "footer.tmpl"),
|
||||||
|
filepath.Join(templatesDir, "include", "render.tmpl"),
|
||||||
filepath.Join(templatesDir, "base.tmpl"),
|
filepath.Join(templatesDir, "base.tmpl"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -74,6 +76,7 @@ func initPage(path, key string) {
|
||||||
pages[key] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
|
pages[key] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
|
||||||
path,
|
path,
|
||||||
filepath.Join(templatesDir, "include", "footer.tmpl"),
|
filepath.Join(templatesDir, "include", "footer.tmpl"),
|
||||||
|
filepath.Join(templatesDir, "include", "render.tmpl"),
|
||||||
filepath.Join(templatesDir, "base.tmpl"),
|
filepath.Join(templatesDir, "base.tmpl"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -87,6 +90,7 @@ func initUserPage(path, key string) {
|
||||||
path,
|
path,
|
||||||
filepath.Join(templatesDir, "user", "include", "header.tmpl"),
|
filepath.Join(templatesDir, "user", "include", "header.tmpl"),
|
||||||
filepath.Join(templatesDir, "user", "include", "footer.tmpl"),
|
filepath.Join(templatesDir, "user", "include", "footer.tmpl"),
|
||||||
|
filepath.Join(templatesDir, "user", "include", "render.tmpl"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,17 +46,8 @@
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>{{end}}
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>{{end}}
|
||||||
|
|
||||||
|
|
||||||
{{if .Collection.CodeHighlight}}
|
<!-- Add highlighting logic -->
|
||||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/atom-one-light.min.css" />
|
{{template "highlighting" .}}
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
|
|
||||||
<script>
|
|
||||||
addEventListener('load', function () {
|
|
||||||
var x = document.querySelectorAll("code[class^='language-']");
|
|
||||||
for (i=0; i<x.length; i++) {
|
|
||||||
hljs.highlightBlock(x[i]);
|
|
||||||
}});
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body id="post">
|
<body id="post">
|
||||||
|
|
|
@ -45,18 +45,8 @@
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>{{end}}
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>{{end}}
|
||||||
|
|
||||||
{{if .CodeHighlight}}
|
<!-- Add highlighting logic -->
|
||||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/atom-one-light.min.css" />
|
{{template "highlighting" . }}
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
|
|
||||||
<script>
|
|
||||||
addEventListener('load', function () {
|
|
||||||
var x = document.querySelectorAll("code[class^='language-']");
|
|
||||||
for (i=0; i<x.length; i++) {
|
|
||||||
hljs.highlightBlock(x[i]);
|
|
||||||
}});
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body id="subpage">
|
<body id="subpage">
|
||||||
|
|
|
@ -44,17 +44,9 @@
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>{{end}}
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>{{end}}
|
||||||
|
|
||||||
|
|
||||||
{{if .CodeHighlight}}
|
<!-- Add highlighting logic -->
|
||||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/atom-one-light.min.css" />
|
{{template "highlighting" . }}
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
|
|
||||||
<script>
|
|
||||||
addEventListener('load', function () {
|
|
||||||
var x = document.querySelectorAll("code[class^='language-']");
|
|
||||||
for (i=0; i<x.length; i++) {
|
|
||||||
hljs.highlightBlock(x[i]);
|
|
||||||
}});
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
||||||
</head>
|
</head>
|
||||||
<body id="collection" itemscope itemtype="http://schema.org/WebPage">
|
<body id="collection" itemscope itemtype="http://schema.org/WebPage">
|
||||||
{{if or .IsOwner .SingleUser}}<nav id="manage"><ul>
|
{{if or .IsOwner .SingleUser}}<nav id="manage"><ul>
|
||||||
|
|
14
templates/include/render.tmpl
Normal file
14
templates/include/render.tmpl
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!-- Miscelaneous render related template parts we use multiple times -->
|
||||||
|
{{define "highlighting"}}
|
||||||
|
<!-- TODO: make this conditional on presence of code blocks -->
|
||||||
|
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/atom-one-light.min.css"/>
|
||||||
|
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
addEventListener('load', function () {
|
||||||
|
var x = document.querySelectorAll("code[class^='language-']");
|
||||||
|
for (i=0; i<x.length; i++) {
|
||||||
|
hljs.highlightBlock(x[i]);
|
||||||
|
}});
|
||||||
|
</script>
|
||||||
|
{{end}}
|
|
@ -32,21 +32,8 @@
|
||||||
<meta property="og:image" content="https://write.as/img/w-sq-light.png">
|
<meta property="og:image" content="https://write.as/img/w-sq-light.png">
|
||||||
{{if .Author}}<meta property="article:author" content="https://{{.Author}}" />{{end}}
|
{{if .Author}}<meta property="article:author" content="https://{{.Author}}" />{{end}}
|
||||||
|
|
||||||
|
<!-- Add highlighting logic -->
|
||||||
<!-- Collection not known during single User draft? this test feels wrong -->
|
{{template "highlighting" .}}
|
||||||
{{if not .SingleUser }}
|
|
||||||
{{if .Collection.CodeHighlight}}
|
|
||||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/atom-one-light.min.css" />
|
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
|
|
||||||
<script>
|
|
||||||
addEventListener('load', function () {
|
|
||||||
var x = document.querySelectorAll("code[class^='language-']");
|
|
||||||
for (i=0; i<x.length; i++) {
|
|
||||||
hljs.highlightBlock(x[i]);
|
|
||||||
}});
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body id="post">
|
<body id="post">
|
||||||
|
|
Loading…
Add table
Reference in a new issue