jekyll-datapage_gen
jekyll-datapage_gen copied to clipboard
Generate pages with multi-level path
Let's say I want to generate pages on the following URLs: /animal/mammal/1/whale /animal/mammal/2/tiger /animal/reptile/3/snake
The directory pattern would have to be /animal/{group}/{id}/{name} where input data is an array of animals. The directory does not support patterns.
I have tried to create an object property with the value /animal/mammal/1/whale. That doesn't work either, pages are placed in the folder animalmammal1whale, i.e., slashes are stripped.
+1 for this
pull requests #63 seems to be doing what you are asking. Quite some time passed by, I hope the solution is still relevant.
pull requests #63 seems to be doing what you are asking. Quite some time passed by, I hope the solution is still relevant.
The way I understand it, @migpimenta is asking for a way to have /animal/mammal/whale/
all built from data, whereas the #63 merge pertains to creating a page called animal_mammal_whale
.
How can we achieve the former result with proper nested directories?
Thanks, now I get it, different label assigned (... easier than actually solving the issue ;-))
@migpimenta @kateho @tjkohli
Its not fully tested ("it's working for me") but this diff may allow what is asking.
https://github.com/HXL-CPLP/Auxilium-Humanitarium-API/commit/0891b72a066bd2b0ce2ad700a6888c04f79b9af5#diff-c1005e95bd3da19bb281fd99bbdd51ee66b5725a5e384d291bf30246310cbc6c
This link may show the difference https://www.diffchecker.com/ZsMpGYvp.
# _config.yml
# @see https://github.com/avillafiorita/jekyll-datapage_gen
page_gen-dirs: true
page_gen:
- data: 'api'
template: 'api'
name_expr: "record['uid'].split('/').last"
dir_expr: "record['uid'].chomp(record['uid'].split('/').last + '/')"
# _data/api.yml
### [linguam]/api/UN ___________________________________________________________
## -----------------------------------------------------------------------------
- x-default: /mul/api/UN/HDX/
uid: /mul/api/UN/HDX/
linguam: mul
typum: api
gid: UN
# lid: HDX
title: "Index: HDX"
noindex: true
- x-default: /mul/api/UN/HDX/
uid: /eng/api/UN/humanitarian-data-exchange/
linguam: eng
typum: api
gid: UN
# lid: HDX
openapi_filum: /api/UN/HDX/eng/openapi.yaml
slug: humanitarian-data-exchange
title: HDX - The Humanitarian Data Exchange API
noindex: true
## -----------------------------------------------------------------------------
- x-default: /mul/api/UN/reliefweb/
uid: /mul/api/UN/reliefweb/
linguam: mul
typum: api
gid: UN
# lid: reliefweb
title: "Index: ReliefWeb"
noindex: true
- x-default: /mul/api/UN/reliefweb/
uid: /eng/api/UN/reliefweb/
linguam: eng
typum: api
gid: UN
# lid: ReliefWeb
openapi_filum: /api/UN/reliefweb/eng/openapi.yaml
slug: reliefweb
title: ReliefWeb - Informing humanitarians worldwide
# title: ReliefWeb - Informing humanitarians worldwide
noindex: true
(...)
Is generating a sitemap like this
<!--
typum: api
-->
<url>
<loc>https://hapi.etica.ai/mul/api/UN/hdx/</loc>
<lastmod>2021-05-17T22:44:58-03:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.3</priority>
<xhtml:link
rel="alternate"
hreflang="x-default"
href="https://hapi.etica.ai/mul/api/UN/HDX/" />
</url>
<url>
<loc>https://hapi.etica.ai/eng/api/UN/humanitarian-data-exchange/</loc>
<lastmod>2021-05-17T22:44:58-03:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.3</priority>
<xhtml:link
rel="alternate"
hreflang="x-default"
href="https://hapi.etica.ai/mul/api/UN/HDX/" />
</url>
<url>
<loc>https://hapi.etica.ai/mul/api/UN/reliefweb/</loc>
<lastmod>2021-05-17T22:44:58-03:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.3</priority>
<xhtml:link
rel="alternate"
hreflang="x-default"
href="https://hapi.etica.ai/mul/api/UN/reliefweb/" />
</url>
<url>
<loc>https://hapi.etica.ai/eng/api/UN/reliefweb/</loc>
<lastmod>2021-05-17T22:44:58-03:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.3</priority>
<xhtml:link
rel="alternate"
hreflang="x-default"
href="https://hapi.etica.ai/mul/api/UN/reliefweb/" />
</url>
Comments
I may need to make a few other changes (so lastest file on the the repository may have some other changes), but if someone is in a hurry,this approach could work.
Note that the
name_expr: "record['uid'].split('/').last"
dir_expr: "record['uid'].chomp(record['uid'].split('/').last + '/')"
is a bit hacky way to use a single variable to split between the folder and the name (so most people may not need to need it. Also, this likely to break with the datapage_url (at least I did not tested)
Also, great project @avillafiorita !
avillafiorita on 16 Oct 2020 Thanks, now I get it, different label assigned (... easier than actually solving the issue ;-))
Yes! Actually, looking at the code, it was the same logic made by @DanielJDufour, so mostly is his credits.
@fititnt , thank you. I appreciate the kind words :-)
+1
This was very useful, thank you. I was able to output multiple related renderings of records, grouped by directory, which really simplifies the output layout.