jekyll-datapage_gen icon indicating copy to clipboard operation
jekyll-datapage_gen copied to clipboard

Generate pages with multi-level path

Open migpimenta opened this issue 5 years ago • 9 comments

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.

migpimenta avatar Feb 25 '19 17:02 migpimenta

+1 for this

kateho avatar Jul 06 '19 15:07 kateho

pull requests #63 seems to be doing what you are asking. Quite some time passed by, I hope the solution is still relevant.

avillafiorita avatar Jun 13 '20 15:06 avillafiorita

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?

tjkohli avatar Aug 30 '20 18:08 tjkohli

Thanks, now I get it, different label assigned (... easier than actually solving the issue ;-))

avillafiorita avatar Oct 16 '20 09:10 avillafiorita

@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 !

fititnt avatar May 18 '21 02:05 fititnt

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 avatar May 18 '21 02:05 fititnt

@fititnt , thank you. I appreciate the kind words :-)

DanielJDufour avatar May 19 '21 22:05 DanielJDufour

+1

ryanwoldatwork avatar Feb 17 '22 06:02 ryanwoldatwork

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.

probablykory avatar Jun 15 '23 17:06 probablykory