parent
6c3f985d1f
commit
4041868a9f
@ -54,15 +54,16 @@ func cleanUpMapValue(v interface{}) interface{} {
|
|||||||
// CollectionConfig describes a collection
|
// CollectionConfig describes a collection
|
||||||
type CollectionConfig struct {
|
type CollectionConfig struct {
|
||||||
Name *string `yaml:"Name"`
|
Name *string `yaml:"Name"`
|
||||||
EntriesJSON *string `yaml:"EntriesJSON"`
|
URL *string `yaml:"URL"`
|
||||||
NavTemplate *struct {
|
NavTemplate *struct {
|
||||||
GoTo string `yaml:"GoTo"`
|
EntriesAttribute string `yaml:"EntriesAttribute"`
|
||||||
Navname string `yaml:"Navname"`
|
GoTo string `yaml:"GoTo"`
|
||||||
Body string `yaml:"Body"`
|
Navname string `yaml:"Navname"`
|
||||||
DataKey string `yaml:"DataKey"`
|
Body string `yaml:"Body"`
|
||||||
Hidden bool `yaml:"Hidden"`
|
DataKey string `yaml:"DataKey"`
|
||||||
Template string `yaml:"Template"`
|
Hidden bool `yaml:"Hidden"`
|
||||||
Recursive bool `yaml:"Recursive"`
|
Template string `yaml:"Template"`
|
||||||
|
Recursive bool `yaml:"Recursive"`
|
||||||
} `yaml:"NavTemplate"`
|
} `yaml:"NavTemplate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package helper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -100,7 +99,7 @@ func fillNodeConfig(node *config.PathConfigTree, inBase, outBase, dir string, co
|
|||||||
if colConfig.Name == nil || *colConfig.Name == "" {
|
if colConfig.Name == nil || *colConfig.Name == "" {
|
||||||
Log.Panicf("missing Name in collection config in '%s'", inPath)
|
Log.Panicf("missing Name in collection config in '%s'", inPath)
|
||||||
}
|
}
|
||||||
if colConfig.EntriesJSON == nil || *colConfig.EntriesJSON == "" {
|
if colConfig.URL == nil || *colConfig.URL == "" {
|
||||||
Log.Panicf("missing EntriesJSON in collection config in '%s'", inPath)
|
Log.Panicf("missing EntriesJSON in collection config in '%s'", inPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,37 +108,73 @@ func fillNodeConfig(node *config.PathConfigTree, inBase, outBase, dir string, co
|
|||||||
node.ColMap = make(config.MapString)
|
node.ColMap = make(config.MapString)
|
||||||
}
|
}
|
||||||
ctx := newContext()
|
ctx := newContext()
|
||||||
jsonStr, err := pongo2.RenderTemplateString(*colConfig.EntriesJSON, ctx)
|
ctx["This"] = node.Config.This
|
||||||
|
ctx["Data"] = node.Config.Data
|
||||||
|
|
||||||
|
url, err := pongo2.RenderTemplateString(*colConfig.URL, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Panicf("invalid template string in '%s': %s", inPath, err)
|
Log.Panicf("invalid template string for Collection Element.URL in '%s': %s", inPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var colSlice []config.MapString
|
colData := jsonWebRequest(url)
|
||||||
err = json.Unmarshal([]byte(jsonStr), &colSlice)
|
node.ColMap[*colConfig.Name] = colData
|
||||||
if err != nil {
|
|
||||||
Log.Panicf("invalid JSON in EntriesJSON in '%s': %s", inPath, err)
|
|
||||||
}
|
|
||||||
node.ColMap[*colConfig.Name] = colSlice
|
|
||||||
//node.ColMap[*colConfig.Name] = jsonWebRequest(*colConfig.URL)
|
|
||||||
|
|
||||||
if navT := colConfig.NavTemplate; navT != nil {
|
if navT := colConfig.NavTemplate; navT != nil {
|
||||||
tpl := navT.Template
|
var entries []interface{}
|
||||||
if tpl == "" {
|
var ok bool
|
||||||
tpl = *newConfig.Template
|
if navT.EntriesAttribute != "" {
|
||||||
|
var colDataMap map[string]interface{}
|
||||||
|
if colDataMap, ok = colData.(map[string]interface{}); ok {
|
||||||
|
entries, ok = colDataMap[navT.EntriesAttribute].([]interface{})
|
||||||
|
if !ok {
|
||||||
|
Log.Debug(spew.Sdump(colDataMap))
|
||||||
|
Log.Panicf("invalid json data in [%s] from url '%s' for entries", navT.EntriesAttribute, url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
entries, ok = colData.([]interface{})
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
Log.Debug(spew.Sdump(colData))
|
||||||
|
Log.Panicf("invalid json data from url '%s', need array of objects for entries or object with configured NavTemplate.EntriesAttribute", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// build navigation with detail sites
|
// build navigation with detail sites
|
||||||
for _, colEl := range colSlice {
|
for idx, colEl := range entries {
|
||||||
ctxE := make(pongo2.Context)
|
ctxE := make(pongo2.Context)
|
||||||
err := config.Merge(&ctxE, ctx)
|
err := config.Merge(&ctxE, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Panicf("could not merge context in '%s': %s", inPath, err)
|
Log.Panicf("could not merge context in '%s': %s", inPath, err)
|
||||||
}
|
}
|
||||||
err = config.Merge(&ctxE, pongo2.Context(colEl))
|
var jsonCtx map[string]interface{}
|
||||||
|
if jsonCtx, ok = colEl.(map[string]interface{}); !ok {
|
||||||
|
Log.Debug(spew.Sdump(colEl))
|
||||||
|
Log.Panicf("no json object for entry index %d from url '%s'", idx, url)
|
||||||
|
}
|
||||||
|
err = config.Merge(&ctxE, pongo2.Context(jsonCtx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Panicf("could not merge context in '%s': %s", inPath, err)
|
Log.Panicf("could not merge context in '%s': %s", inPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tpl := ""
|
||||||
|
if navT.Template != "" {
|
||||||
|
tpl, err = pongo2.RenderTemplateString(navT.Template, ctxE)
|
||||||
|
if err != nil {
|
||||||
|
Log.Panicf("invalid template string for NavTemplate.Template in '%s': %s", inPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tpl == "" {
|
||||||
|
tpl = *newConfig.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
dataKey := ""
|
||||||
|
if navT.DataKey != "" {
|
||||||
|
dataKey, err = pongo2.RenderTemplateString(navT.DataKey, ctxE)
|
||||||
|
if err != nil {
|
||||||
|
Log.Panicf("invalid template string for NavTemplate.DataKey in '%s': %s", inPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goTo, err := pongo2.RenderTemplateString(navT.GoTo, ctxE)
|
goTo, err := pongo2.RenderTemplateString(navT.GoTo, ctxE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Panicf("invalid template string for NavTemplate.GoTo in '%s': %s", inPath, err)
|
Log.Panicf("invalid template string for NavTemplate.GoTo in '%s': %s", inPath, err)
|
||||||
@ -172,7 +207,7 @@ func fillNodeConfig(node *config.PathConfigTree, inBase, outBase, dir string, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add2Nav(node, node.Config, tpl, goTo, navname, colEl, navT.DataKey, body, navT.Hidden)
|
add2Nav(node, node.Config, tpl, goTo, navname, colEl, dataKey, body, navT.Hidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func jsonWebRequest(url string) config.MapString {
|
func jsonWebRequest(url string) interface{} {
|
||||||
Log.Noticef("requesting url via GET %s", url)
|
Log.Noticef("requesting url via GET %s", url)
|
||||||
|
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
@ -38,13 +38,20 @@ func jsonWebRequest(url string) config.MapString {
|
|||||||
Log.Panicf("is not json '%s' from url '%s'", contentType, url)
|
Log.Panicf("is not json '%s' from url '%s'", contentType, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonMap := make(config.MapString)
|
jsonMap := make(map[string]interface{})
|
||||||
err = json.Unmarshal(body, &jsonMap)
|
err = json.Unmarshal(body, &jsonMap)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
Log.Panicf("could not read json from '%s': %s", url, err)
|
return jsonMap
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonMap
|
jsonArrayMap := make([]map[string]interface{}, 0)
|
||||||
|
err = json.Unmarshal(body, &jsonArrayMap)
|
||||||
|
if err == nil {
|
||||||
|
return jsonArrayMap
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Panicf("could not read json from '%s': invalid type", url)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestFn will make a web request and returns map[string]interface form pongo2
|
// RequestFn will make a web request and returns map[string]interface form pongo2
|
||||||
|
@ -3,6 +3,11 @@ GET https://mark2web.basiscms.de/api/collections/get/mark2webBlog
|
|||||||
&limit=101
|
&limit=101
|
||||||
&token=89ff216524093123bf7a0a10f7b273
|
&token=89ff216524093123bf7a0a10f7b273
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
&filter[link._id]=5c76a0f4643334fe0400039c
|
||||||
|
&filter[published]=true
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
GET https://mark2web.basiscms.de/api/imagestyles/style/klein
|
GET https://mark2web.basiscms.de/api/imagestyles/style/klein
|
||||||
|
@ -63,4 +63,4 @@ Weitere Pakete, die verwendet wurden finden Sie in den Quellen.
|
|||||||
|
|
||||||
Diese Website wurde selbst mit mark2web generiert. Der entsprechende Quellcode, sowie die Quellen zu mark2web finden Sie unter:
|
Diese Website wurde selbst mit mark2web generiert. Der entsprechende Quellcode, sowie die Quellen zu mark2web finden Sie unter:
|
||||||
|
|
||||||
**https://gitbase.de/apairon/mark2web**
|
**[https://gitbase.de/apairon/mark2web](5c76a0f4643334fe0400039c)**
|
@ -1,8 +1,9 @@
|
|||||||
This:
|
This:
|
||||||
Collections:
|
Collections:
|
||||||
- Name: blog1st
|
- Name: blog1st
|
||||||
EntriesJSON: '{{ fnRequest("https://mark2web.basiscms.de/api/collections/get/mark2webBlog?token=89ff216524093123bf7a0a10f7b273&filter[published]=true&sort[date]=-1&skip=0&limit=1").entries|json }}'
|
URL: 'https://mark2web.basiscms.de/api/collections/get/mark2webBlog?token={{ Data.token }}&filter[published]=true&sort[date]=-1&skip=0&limit=1'
|
||||||
NavTemplate:
|
NavTemplate:
|
||||||
|
EntriesAttribute: entries
|
||||||
GoTo: '{{ date }}-{{ title }}'
|
GoTo: '{{ date }}-{{ title }}'
|
||||||
Navname: '{{ title }}'
|
Navname: '{{ title }}'
|
||||||
Body: '{{ body }}'
|
Body: '{{ body }}'
|
||||||
@ -11,8 +12,9 @@ This:
|
|||||||
Hidden: true # hide from nav, but use this feature for rendering detail sites
|
Hidden: true # hide from nav, but use this feature for rendering detail sites
|
||||||
|
|
||||||
- Name: blog1skip
|
- Name: blog1skip
|
||||||
EntriesJSON: '{{ fnRequest("https://mark2web.basiscms.de/api/collections/get/mark2webBlog?token=89ff216524093123bf7a0a10f7b273&filter[published]=true&sort[date]=-1&skip=1&limit=100").entries|json }}'
|
URL: 'https://mark2web.basiscms.de/api/collections/get/mark2webBlog?token={{ Data.token }}&filter[published]=true&sort[date]=-1&skip=1&limit=100'
|
||||||
NavTemplate:
|
NavTemplate:
|
||||||
|
EntriesAttribute: entries
|
||||||
GoTo: '{{ date }}-{{ title }}'
|
GoTo: '{{ date }}-{{ title }}'
|
||||||
Navname: '{{ title }}'
|
Navname: '{{ title }}'
|
||||||
Body: '{{ body }}'
|
Body: '{{ body }}'
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block part0 %}
|
{% block part0 %}
|
||||||
{{ Body }}
|
{{ Body }}
|
||||||
{% for e in NavElement.ColMap.blog1st %}
|
{% for e in NavElement.ColMap.blog1st.entries %}
|
||||||
<h2>
|
<h2>
|
||||||
{{ e.title }}
|
{{ e.title }}
|
||||||
<div class="datum">{{ e.date|datum }}</div>
|
<div class="datum">{{ e.date|datum }}</div>
|
||||||
@ -18,7 +18,7 @@
|
|||||||
{% comment %}
|
{% comment %}
|
||||||
limit wird für skip in Query gebraucht
|
limit wird für skip in Query gebraucht
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
{% for e in NavElement.ColMap.blog1skip %}
|
{% for e in NavElement.ColMap.blog1skip.entries %}
|
||||||
<h2>
|
<h2>
|
||||||
{{ e.title }}
|
{{ e.title }}
|
||||||
<div class="datum">{{ e.date|datum }}</div>
|
<div class="datum">{{ e.date|datum }}</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user