fnRequest, pongo2-addons added
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4c2a13d6b5
commit
8f1345d4aa
15
.gitmodules
vendored
15
.gitmodules
vendored
@ -46,3 +46,18 @@
|
|||||||
[submodule "vendor/github.com/rainycape/unidecode"]
|
[submodule "vendor/github.com/rainycape/unidecode"]
|
||||||
path = vendor/github.com/rainycape/unidecode
|
path = vendor/github.com/rainycape/unidecode
|
||||||
url = https://github.com/rainycape/unidecode
|
url = https://github.com/rainycape/unidecode
|
||||||
|
[submodule "vendor/github.com/flosch/pongo2-addons"]
|
||||||
|
path = vendor/github.com/flosch/pongo2-addons
|
||||||
|
url = https://github.com/flosch/pongo2-addons
|
||||||
|
[submodule "vendor/github.com/extemporalgenome/slug"]
|
||||||
|
path = vendor/github.com/extemporalgenome/slug
|
||||||
|
url = https://github.com/extemporalgenome/slug
|
||||||
|
[submodule "vendor/golang.org/x/text"]
|
||||||
|
path = vendor/golang.org/x/text
|
||||||
|
url = https://go.googlesource.com/text
|
||||||
|
[submodule "vendor/github.com/flosch/go-humanize"]
|
||||||
|
path = vendor/github.com/flosch/go-humanize
|
||||||
|
url = https://github.com/flosch/go-humanize
|
||||||
|
[submodule "vendor/github.com/russross/blackfriday"]
|
||||||
|
path = vendor/github.com/russross/blackfriday
|
||||||
|
url = https://github.com/russross/blackfriday
|
||||||
|
17
helper/template_filters.go
Normal file
17
helper/template_filters.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/flosch/pongo2"
|
||||||
|
_ "github.com/flosch/pongo2-addons"
|
||||||
|
"gopkg.in/russross/blackfriday.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
pongo2.ReplaceFilter("markdown", MarkdownFilter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkdownFilter is a pongo2 filter, which converts markdown to html
|
||||||
|
func MarkdownFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||||
|
html := blackfriday.Run([]byte(in.String()))
|
||||||
|
return pongo2.AsSafeValue(string(html)), nil
|
||||||
|
}
|
51
helper/template_functions.go
Normal file
51
helper/template_functions.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
"github.com/flosch/pongo2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request will make a web request and returns map[string]interface form pongo2
|
||||||
|
func Request(url *pongo2.Value, args ...*pongo2.Value) *pongo2.Value {
|
||||||
|
u := url.String()
|
||||||
|
fmt.Printf("request GET %s\n", u)
|
||||||
|
|
||||||
|
resp, err := http.Get(u)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
spew.Dump(string(body))
|
||||||
|
|
||||||
|
if resp.StatusCode >= 400 {
|
||||||
|
panic(resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
contentType := resp.Header.Get("Content-Type")
|
||||||
|
|
||||||
|
if strings.Contains(contentType, "json") {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
panic("invalid content-type")
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonMap := make(map[string]interface{})
|
||||||
|
err = json.Unmarshal(body, &jsonMap)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pongo2.AsValue(jsonMap)
|
||||||
|
}
|
4
main.go
4
main.go
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
|
|
||||||
|
"gitbase.de/apairon/mark2web/helper"
|
||||||
"github.com/Depado/bfchroma"
|
"github.com/Depado/bfchroma"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
@ -540,6 +541,9 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L]
|
|||||||
ctx["Body"] = pongo2.AsSafeValue(string(html))
|
ctx["Body"] = pongo2.AsSafeValue(string(html))
|
||||||
ctx["BodyParts"] = htmlParts
|
ctx["BodyParts"] = htmlParts
|
||||||
|
|
||||||
|
// register functions
|
||||||
|
ctx["fnRequest"] = helper.Request
|
||||||
|
|
||||||
result, err := template.Execute(ctx)
|
result, err := template.Execute(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("could not execute template '%s' for input file '%s': %s", templateFile, inFile, err)
|
log.Panicf("could not execute template '%s' for input file '%s': %s", templateFile, inFile, err)
|
||||||
|
1
test.rest
Normal file
1
test.rest
Normal file
@ -0,0 +1 @@
|
|||||||
|
POST https://cockpit.basiscms.de/api/collections/get/mark2webBlog?filter[published]=true&sort[date]=-1&limit=1&skip=1
|
1
vendor/github.com/extemporalgenome/slug
generated
vendored
Submodule
1
vendor/github.com/extemporalgenome/slug
generated
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 0320c85e32e0015b090f08a5d1324d5ab6094f07
|
1
vendor/github.com/flosch/go-humanize
generated
vendored
Submodule
1
vendor/github.com/flosch/go-humanize
generated
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 3ba51eabe50663842d569003bab93fc256883173
|
1
vendor/github.com/flosch/pongo2-addons
generated
vendored
Submodule
1
vendor/github.com/flosch/pongo2-addons
generated
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 86b9b7b8051253fbb41b3fff8a8f5cc9c300305e
|
1
vendor/github.com/russross/blackfriday
generated
vendored
Submodule
1
vendor/github.com/russross/blackfriday
generated
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit a477dd1646916742841ed20379f941cfa6c5bb6f
|
1
vendor/golang.org/x/text
generated
vendored
Submodule
1
vendor/golang.org/x/text
generated
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit d14c52b222ee852cdba8b07206ca0c614b389876
|
@ -1,9 +1,5 @@
|
|||||||
# Blog
|
---
|
||||||
|
Template: base_blog.html
|
||||||
## 20.02.2019 erstes Release veröffentlicht
|
|
||||||
|
|
||||||
Das erste Release von **mark2web** ist fertig. Einfache Websites lassen sich damit auf unkomplizierte Weise generieren. Später folgt die Möglichkeit Listen, Galerien und Formulare zu generieren.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
# Blog
|
||||||
Das Release kann unter der [Release-Seite](https://gitbase.de/apairon/mark2web/releases) heruntergeladen werden.
|
|
@ -72,7 +72,9 @@
|
|||||||
<!-- ========== Content First ========== -->
|
<!-- ========== Content First ========== -->
|
||||||
<div class="contentfirst section_padding white_color ">
|
<div class="contentfirst section_padding white_color ">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
{% block part0 %}
|
||||||
{{ BodyParts.0 }}
|
{{ BodyParts.0 }}
|
||||||
|
{% endblock part0 %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -80,7 +82,9 @@
|
|||||||
<div class="maincontent">
|
<div class="maincontent">
|
||||||
<div class="white_section section_padding">
|
<div class="white_section section_padding">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
{% block part1 %}
|
||||||
{{ BodyParts.1 }}
|
{{ BodyParts.1 }}
|
||||||
|
{% endblock part1 %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -109,6 +113,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- ========== Footer ========== -->
|
<!-- ========== Footer ========== -->
|
||||||
<footer id="footer">
|
<footer id="footer">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
31
website/templates/base_blog.html
Normal file
31
website/templates/base_blog.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block part0 %}
|
||||||
|
{{ Body }}
|
||||||
|
{% for e in fnRequest("https://cockpit.basiscms.de/api/collections/get/mark2webBlog?filter[published]=true&sort[date]=-1&limit=1").entries %}
|
||||||
|
<h2>
|
||||||
|
<small>{{ e.date }}</small>
|
||||||
|
{{ e.title }}
|
||||||
|
</h2>
|
||||||
|
{{ e.teaser|markdown }}
|
||||||
|
{% if e.body %}
|
||||||
|
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock part0 %}
|
||||||
|
|
||||||
|
{% block part1 %}
|
||||||
|
{% comment %}
|
||||||
|
limit wird für skip in Query gebraucht
|
||||||
|
{% endcomment %}
|
||||||
|
{% for e in fnRequest("https://cockpit.basiscms.de/api/collections/get/mark2webBlog?filter[published]=true&sort[date]=-1&skip=1&limit=100").entries %}
|
||||||
|
<h2>
|
||||||
|
<small>{{ e.date }}</small>
|
||||||
|
{{ e.title }}
|
||||||
|
</h2>
|
||||||
|
{{ e.teaser|markdown }}
|
||||||
|
{% if e.body %}
|
||||||
|
<a href="{{ e.title|slugify }}" class="btn">mehr lesen</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock part1 %}
|
Loading…
Reference in New Issue
Block a user