Procházet zdrojové kódy

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
pull/31/head
Marcel van der Boom před 5 roky
rodič
revize
a82882fddc
6 změnil soubory, kde provedl 27 přidání a 49 odebrání
  1. +4
    -0
      templates.go
  2. +2
    -11
      templates/collection-post.tmpl
  3. +2
    -12
      templates/collection-tags.tmpl
  4. +3
    -11
      templates/collection.tmpl
  5. +14
    -0
      templates/include/render.tmpl
  6. +2
    -15
      templates/post.tmpl

+ 4
- 0
templates.go Zobrazit soubor

@@ -55,12 +55,14 @@ func initTemplate(name string) {
filepath.Join(templatesDir, name+".tmpl"),
filepath.Join(templatesDir, "include", "posts.tmpl"),
filepath.Join(templatesDir, "include", "footer.tmpl"),
filepath.Join(templatesDir, "include", "render.tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
))
} else {
templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
filepath.Join(templatesDir, name+".tmpl"),
filepath.Join(templatesDir, "include", "footer.tmpl"),
filepath.Join(templatesDir, "include", "render.tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
))
}
@@ -74,6 +76,7 @@ func initPage(path, key string) {
pages[key] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
path,
filepath.Join(templatesDir, "include", "footer.tmpl"),
filepath.Join(templatesDir, "include", "render.tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
))
}
@@ -87,6 +90,7 @@ func initUserPage(path, key string) {
path,
filepath.Join(templatesDir, "user", "include", "header.tmpl"),
filepath.Join(templatesDir, "user", "include", "footer.tmpl"),
filepath.Join(templatesDir, "user", "include", "render.tmpl"),
))
}



+ 2
- 11
templates/collection-post.tmpl Zobrazit soubor

@@ -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}}


{{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}}
<!-- Add highlighting logic -->
{{template "highlighting" .}}

</head>
<body id="post">


+ 2
- 12
templates/collection-tags.tmpl Zobrazit soubor

@@ -45,18 +45,8 @@
</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}}

{{if .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}}

<!-- Add highlighting logic -->
{{template "highlighting" . }}

</head>
<body id="subpage">


+ 3
- 11
templates/collection.tmpl Zobrazit soubor

@@ -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}}


{{if .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}}
<!-- Add highlighting logic -->
{{template "highlighting" . }}

</head>
<body id="collection" itemscope itemtype="http://schema.org/WebPage">
{{if or .IsOwner .SingleUser}}<nav id="manage"><ul>


+ 14
- 0
templates/include/render.tmpl Zobrazit soubor

@@ -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}}

+ 2
- 15
templates/post.tmpl Zobrazit soubor

@@ -32,21 +32,8 @@
<meta property="og:image" content="https://write.as/img/w-sq-light.png">
{{if .Author}}<meta property="article:author" content="https://{{.Author}}" />{{end}}


<!-- Collection not known during single User draft? this test feels wrong -->
{{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}}
<!-- Add highlighting logic -->
{{template "highlighting" .}}

</head>
<body id="post">


Načítá se…
Zrušit
Uložit