fnRequest, pongo2-addons added
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Sebastian Frank 2019-02-27 15:58:10 +01:00
parent 4c2a13d6b5
commit 8f1345d4aa
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3
13 changed files with 132 additions and 7 deletions

15
.gitmodules vendored
View File

@ -46,3 +46,18 @@
[submodule "vendor/github.com/rainycape/unidecode"]
path = vendor/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

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

View 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)
}

View File

@ -13,6 +13,7 @@ import (
"github.com/imdario/mergo"
"gitbase.de/apairon/mark2web/helper"
"github.com/Depado/bfchroma"
"github.com/davecgh/go-spew/spew"
"github.com/flosch/pongo2"
@ -540,6 +541,9 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L]
ctx["Body"] = pongo2.AsSafeValue(string(html))
ctx["BodyParts"] = htmlParts
// register functions
ctx["fnRequest"] = helper.Request
result, err := template.Execute(ctx)
if err != nil {
log.Panicf("could not execute template '%s' for input file '%s': %s", templateFile, inFile, err)

1
test.rest Normal file
View 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

@ -0,0 +1 @@
Subproject commit 0320c85e32e0015b090f08a5d1324d5ab6094f07

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

@ -0,0 +1 @@
Subproject commit 86b9b7b8051253fbb41b3fff8a8f5cc9c300305e

1
vendor/github.com/russross/blackfriday generated vendored Submodule

@ -0,0 +1 @@
Subproject commit a477dd1646916742841ed20379f941cfa6c5bb6f

1
vendor/golang.org/x/text generated vendored Submodule

@ -0,0 +1 @@
Subproject commit d14c52b222ee852cdba8b07206ca0c614b389876

View File

@ -1,9 +1,5 @@
# Blog
## 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.
---
Template: base_blog.html
Das Release kann unter der [Release-Seite](https://gitbase.de/apairon/mark2web/releases) heruntergeladen werden.
---
# Blog

View File

@ -72,7 +72,9 @@
<!-- ========== Content First ========== -->
<div class="contentfirst section_padding white_color ">
<div class="container">
{% block part0 %}
{{ BodyParts.0 }}
{% endblock part0 %}
</div>
</div>
@ -80,7 +82,9 @@
<div class="maincontent">
<div class="white_section section_padding">
<div class="container">
{% block part1 %}
{{ BodyParts.1 }}
{% endblock part1 %}
</div>
</div>
@ -108,6 +112,7 @@
{% endif %}
</div>
<!-- ========== Footer ========== -->
<footer id="footer">

View 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 %}