Multi theming a good idea?

I have read several posts here on multi theming and would like your advice as perhaps I overlook the obvious.

I have a travel web site with city information where each city has its own page. I am now creating an itinerary builder which makes ajax calls to these pages. However, in the case of the latter I just need the bare content, not the header, footer, images etc. i.e. I would need the scrape the page to get the bare content.

What would be the best way to approach this?

Hugo v0.75.1

Perhaps you could generate HTML and JSON pages for each city.

1 Like

Gosh you guys are brilliant!

One would expect the json output to be simlar to the html version right?

My directory structure is /content/english/states/state/cities/city/etc
e.g uttar-pradesh/cities/agra/hotels

In states my list.json.json lists all the states as expected just like the html version. But from state onwards it lists the data of the directory ahead: e.g. the best places in that state rather than the single state as the html version does. Any idea what I may be doing wrong?

list.json.json file:

{{ define “response” }}
{
{{ with eq .Kind “section”}}
“section” : “{{ $.Section }}”,
{{ end }}
“count” : “{{ len .Data.Pages }}”
,“items” : [
{{ range $i, $e := .Data.Pages }}
{{ if $i }}, {{ end }}{{ .Render “item” }}
{{ end }}
]
}
{{ end }}

hugo v.0.75.1
github: git@github.com:ourmaninindia/odyssey-tours.git

Check out .Pages vs .RegularPages vs .RegularPagesRecursive

I am a bit puzzled by your reference, I only have list pages here and my list.html page uses the same Data.Pages variable as my json mentioned earlier yet .

list.htlm:
{{- $paginator := .Paginate .Data.Pages }}
{{- range $paginator.Pages }}
{{- .Render “summary” }}
{{- end }}
{{- end }}

The json in the root of the section shows “permalink” : “/states/andaman-and-nicobar/” + 30 other states (fine)

The next directory shows “permalink” : “/states/uttar-pradesh/cities/” while I expected to see “permalink” : “/states/uttar-pradesh/” (as did the html version)

sorry if I missed something here.

could you share some of the output json, make it a bit easier to see what’s going on?

sure. This is my github link for the uttar-pradesh directory (the repo should be public):

the html page shows the details for the state Uttar Pradesh
the json shows the next level directory (best cities in…)

{
“data” :
{
“section” : “states”,
“count” : “1”
,“items” : [
{
“title”: “The best places in Uttar Pradesh”,
“date”: “2020-09-21 12:59:23 +0200 CEST”,
“type”: “states”,
“permalink” : “/states/uttar-pradesh/cities/”,
“content” : “”
}
]
}
}

the frontmatter for this should be as below (as reflected by the html) but json takes the next level data

title: “Uttar Pradesh”
subtitle: “The Hindi heartland”
date: 2020-09-21T12:59:23+02:00
draft: false
image: uttar-pradesh.jpg
translationkey: “uttar-pradesh”
id: “state”
layout: “state”
tags: [“States”]

/states/uttar-pradesh is a list type page - content comes from its _index.md.
/states/uttar-pradesh/cities/ is also a list type page - content comes from its _index.md.

Therefore, for the index.json output, both the States and the Cities render from ./layouts/_default/list.json.json, which is doing exactly the same thing for all of them - it’s looping through the .Data.Pages collection for that _index page.

The output json on /states/uttar-pradesh/index.json is showing you exactly what you asked it to - the collection of pages (so happens there is only the 1 sub-dir “Cities”) underneath uttar-pradash.

But you’re actually wanting NOT to loop through the .Data.Pages collection, and instead put out only the CURRENT page’s info. Basically, you’re wanting the same json structure to mean different things depending on where you are in the hierarchy. You can do this, but it’s going to be up to you to code this into your list.json.json template so that it handles each case differently depending on what you want the output to be on each level.

Thanks a ton! I will get to work on that.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.