print toml rewrite...
This commit is contained in:
parent
fc09b7e842
commit
6b640fb137
1 changed files with 70 additions and 106 deletions
|
@ -1,119 +1,83 @@
|
|||
{{- define "print" -}}
|
||||
{{- $currentPage := . -}}
|
||||
{{- $renderPage := "" -}}
|
||||
{{- $populateDict := dict -}}
|
||||
{{- $renderPaths := slice -}}
|
||||
{{- $pagePaths := slice -}}
|
||||
{{- $nestedPagePaths := slice -}}
|
||||
{{- range $printItem := .Params.print -}}
|
||||
{{- with $printItem.render.static -}}
|
||||
{{- $renderPaths = $renderPaths|append . -}}
|
||||
{{- with site.GetPage . -}}
|
||||
{{- $staticPage := . -}}
|
||||
{{- range $printer := $printItem.populate -}}
|
||||
{{- $section := "" -}}
|
||||
{{- range $populateVar, $sectionGraph := $printer -}}
|
||||
{{- if not $sectionGraph -}}
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
{{- if ne $populateVar "exclude" -}}
|
||||
{{- if hasPrefix $sectionGraph "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $sectionGraph) -}}
|
||||
{{- else if strings.Contains $sectionGraph "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $sectionGraph "_")) 0) -}}
|
||||
{{- end -}}
|
||||
{{- with (index $staticPage.Params $sectionGraph) -}}
|
||||
{{- range $page := index $staticPage.Params $sectionGraph -}}
|
||||
{{- $pages := index $populateDict $populateVar| default slice -}}
|
||||
{{- $pages = $pages|append (printf "/%s/%s" $section $page) -}}
|
||||
{{- $populateDict = merge $populateDict (dict $populateVar $pages) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $populateDict = merge $populateDict (dict $populateVar (index $staticPage.Params $sectionGraph)) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- with $printItem.render.loop -}}
|
||||
{{- $loopItem := . -}}
|
||||
{{- with (index $populateDict $loopItem) -}}
|
||||
{{- if not (reflect.IsSlice .) -}}
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
{{- range $pagePath := index $populateDict $loopItem -}}
|
||||
{{- with site.GetPage . -}}
|
||||
{{- $staticPage := . -}}
|
||||
{{- range $printer := $printItem.populate -}}
|
||||
{{- $section := "" -}}
|
||||
{{- range $populateVar, $sectionGraph := $printer -}}
|
||||
{{- if not $sectionGraph -}}
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
{{- if ne $populateVar "exclude" -}}
|
||||
{{- if hasPrefix $sectionGraph "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $sectionGraph) -}}
|
||||
{{- else if strings.Contains $sectionGraph "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $sectionGraph "_")) 0) -}}
|
||||
{{- end -}}
|
||||
{{- with (index $staticPage.Params $sectionGraph) -}}
|
||||
{{- range $page := index $staticPage.Params $sectionGraph -}}
|
||||
{{- $pages := index $populateDict $populateVar| default slice -}}
|
||||
{{- $pages = $pages|append (printf "/%s/%s" $section $page) -}}
|
||||
{{- $populateDict = merge $populateDict (dict $populateVar $pages) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $populateDict = merge $populateDict (dict $populateVar (index $staticPage.Params $sectionGraph)) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- with $printItem.render.loopIn -}}
|
||||
{{- range $printer := $printItem.populate -}}
|
||||
{{- $section := "" -}}
|
||||
{{- range $populateVar, $sectionGraph := $printer -}}
|
||||
{{- $populateDict = merge $populateDict (dict $populateVar $sectionGraph) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $loopParts := split . "." -}}
|
||||
{{- $loopIn := index $loopParts 0 -}}
|
||||
{{- $loopOut := index $loopParts 1 -}}
|
||||
{{- range $i, $page := (index $populateDict $loopIn) -}}
|
||||
{{- $loopInKey := (printf "%s_%d" $loopIn $i) -}}
|
||||
{{- $pages := index $populateDict $loopInKey| default slice -}}
|
||||
{{- with site.GetPage $page -}}
|
||||
{{- $pages = $pages|append $page -}}
|
||||
{{- end -}}
|
||||
{{- $populateDict = merge $populateDict (dict $loopInKey $pages) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- with $printItem.render.loopOut -}}
|
||||
{{- $loopParts := split . "." -}}
|
||||
{{- $loopIn := index $loopParts 1 -}}
|
||||
{{- $loopOut := index $loopParts 0 -}}
|
||||
{{- range $outI, $outPage := (index $populateDict $loopIn) -}}
|
||||
{{- with $page := site.GetPage $outPage -}}
|
||||
{{- $sectionGraph := index $populateDict $loopOut -}}
|
||||
{{- range $inI, $inPage := (index $page.Params $sectionGraph) -}}
|
||||
{{- range $renderItem := $printItem.loop -}}
|
||||
{{- warnf "$renderItem: %s" $renderItem -}}
|
||||
{{- if gt (len $pagePaths) 0 -}}
|
||||
{{- range $nestedPage := $pagePaths -}}
|
||||
{{- with $p := site.GetPage $nestedPage -}}
|
||||
{{- $section := "" -}}
|
||||
{{- if hasPrefix $sectionGraph "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $sectionGraph) -}}
|
||||
{{- else if strings.Contains $sectionGraph "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $sectionGraph "_")) 0) -}}
|
||||
{{- $nestedPagePaths = $nestedPagePaths|append $nestedPage -}}
|
||||
{{- with index $p.Params $renderItem -}}
|
||||
{{- range $page := index $p.Params $renderItem -}}
|
||||
{{- if hasPrefix $renderItem "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $renderItem) -}}
|
||||
{{- else if strings.Contains $renderItem "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $renderItem "_")) 0) -}}
|
||||
{{- end -}}
|
||||
{{- $nestedPagePaths = $nestedPagePaths|append (printf "/%s/%s" $section $page) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $key := (printf "%s_%d" $loopIn $outI) -}}
|
||||
{{- $pages := index $populateDict $key | default slice -}}
|
||||
{{/*- with site.GetPage $inPage -*/}}
|
||||
{{- $pages = $pages|append (printf "/%s/%s" $section $inPage) -}}
|
||||
{{/*- end -*/}}
|
||||
{{- $populateDict = merge $populateDict (dict $key $pages) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if gt (len $nestedPagePaths) 0 -}}
|
||||
{{- $pagePaths = $nestedPagePaths -}}
|
||||
{{- $nestedPagePaths = slice -}}
|
||||
{{- end -}}
|
||||
{{- else if hasPrefix $renderItem "/" -}}
|
||||
{{- with site.GetPage $renderItem -}}
|
||||
{{- $renderPaths = $renderPaths|append $renderItem -}}
|
||||
{{- $renderPage = . -}}
|
||||
{{- end -}}
|
||||
{{- else if $renderPage -}}
|
||||
{{- $section := "" -}}
|
||||
{{- range $page := index $renderPage.Params $renderItem -}}
|
||||
{{- if hasPrefix $renderItem "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $renderItem) -}}
|
||||
{{- else if strings.Contains $renderItem "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $renderItem "_")) 0) -}}
|
||||
{{- end -}}
|
||||
{{- $pagePaths = $pagePaths|append (printf "/%s/%s" $section $page) -}}
|
||||
{{- end -}}
|
||||
{{- $renderPage = "" -}}
|
||||
{{- else if isset $populateDict $renderItem -}}
|
||||
{{- warnf "$populateDict: %s | $renderItem: %s" $populateDict $renderItem -}}
|
||||
{{- range $pagePath := index (index $populateDict $renderItem) "pages" -}}
|
||||
{{- $renderPaths = $renderPaths | append $pagePath -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- with $printItem.populate -}}
|
||||
{{- range $popMap := . -}}
|
||||
{{- range $popKey, $popValue := $popMap -}}
|
||||
{{- $populatePagePaths := index (index $populateDict $popKey) "pages" | default slice -}}
|
||||
{{- range $pagePath := (union $renderPaths $pagePaths) -}}
|
||||
{{- with site.GetPage $pagePath -}}
|
||||
{{- $section := "" -}}
|
||||
{{- with $pages := index .Params $popValue -}}
|
||||
{{- warnf "$popValue: %s" $popValue -}}
|
||||
{{- if hasPrefix $popValue "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $popValue) -}}
|
||||
{{- else if strings.Contains $popValue "_" -}}
|
||||
{{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $popValue "_")) 0) -}}
|
||||
{{- end -}}
|
||||
{{- range $page := $pages -}}
|
||||
{{- $populatePagePaths = $populatePagePaths | append (printf "/%s/%s" $section $page) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $populateDict = merge $populateDict (dict $popKey (dict "graph" $popValue "pages" $populatePagePaths)) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $renderPaths = $renderPaths|append $pagePaths -}}
|
||||
{{- $pagePaths = slice -}}
|
||||
{{- end -}}
|
||||
<p>{{- printf "Populate dict: %s" $populateDict -}}</p>
|
||||
<p>{{- printf "Render paths: %s" $renderPaths -}}</p>
|
||||
{{- printf "%#v" $renderPaths -}}
|
||||
{{- end -}}
|
||||
|
|
Loading…
Add table
Reference in a new issue