Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate pages with multi-level path #57

Open
migpimenta opened this issue Feb 25, 2019 · 10 comments
Open

Generate pages with multi-level path #57

migpimenta opened this issue Feb 25, 2019 · 10 comments

Comments

@migpimenta
Copy link

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.

@kateho
Copy link

kateho commented Jul 6, 2019

+1 for this

@avillafiorita
Copy link
Owner

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

@avillafiorita avillafiorita added the fixed? Issue fixed, waiting for confirmation label Jun 13, 2020
@tjkohli
Copy link

tjkohli commented Aug 30, 2020

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?

@avillafiorita avillafiorita added enhancement and removed fixed? Issue fixed, waiting for confirmation labels Oct 16, 2020
@avillafiorita
Copy link
Owner

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

@fititnt
Copy link

fititnt commented May 18, 2021

@migpimenta @kateho @tjkohli

Its not fully tested ("it's working for me") but this diff may allow what is asking.

HXL-CPLP/Auxilium-Humanitarium-API@0891b72#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
Copy link

fititnt commented May 18, 2021

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.

@DanielJDufour
Copy link
Contributor

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

@ryanwoldatwork
Copy link

+1

ryanwoldatwork added a commit to 18F/analytics.usa.gov that referenced this issue Jun 10, 2023
* remove hard-coded agencies
* remove _agencies and _data-pages collections in favor of _data/agencies.json
* add page-generator-gem
* add page-generator plugin shim from avillafiorita/jekyll-datapage_gen#57
* generate a sitemap
@probablykory
Copy link

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.

@RedaBenh
Copy link

RedaBenh commented Nov 8, 2024

+1
We absolutly need this dir_expr attribute, meanwhile i'm using this file version : https://github.com/18F/analytics.usa.gov/blob/develop/_plugins/jekyll_page_generator.rb
Thanks @ryanwoldatwork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants