scmorrison / uzu

Uzu is a static site generator with built-in web server, file modification watcher, live reload, i18n, themes, multi-page support, inject external data via local Raku module, and external pre/post command execution.
Artistic License 2.0
36 stars 1 forks source link

Support "*_pages" expansion feature in nested variables #26

Closed evanmiller closed 7 years ago

evanmiller commented 7 years ago

It appears the *_pages expansion only works for top-level variables. I have some pages with nested hierarchies of links (e.g. categories/subcategories/sub_pages); it would be great if the algorithm could be applied to nested variables/attributes as well as top-level ones.

scmorrison commented 7 years ago

Hi @evanmiller, can you share an example of a structure you want to support? You can now do something like this:

---
related_pages:
    - page: about
    - page: blog/fiji
    - page: https://www.perl6.org
nested:
    - deep_pages:
        - page: blog/fiji
        - page: about
categories:
    - vacation:
        - vacation_pages:
            - page: index
            - page: about
            - page: blog/fiji
        - road_trips:
            - road_trip_pages:
                - page: pacific_northwest
                - page: australia
                - page: africa
---
evanmiller commented 7 years ago

I'm looking for:

categories:
  - title: General tasks
    category_pages:
      - page: compute/categories
      - page: compute/survival_times
      - page: summary/covariate_partition
      - page: tables/row_multipliers

I updated Uzu, but this still doesn't seem to be working.

scmorrison commented 7 years ago

This structure should work, I just did a copy / paste test and it looks like it is working. Maybe test a full uzu reinstall again. You can access it from {{ category_pages }}.

evanmiller commented 7 years ago

To be clear I want to access it like:

{{#categories}}
<em>{{ title }}</em>
{{#category_pages}}
<li>{{ title }}</li>
{{/category_pages}}
{{/categories}}

Should that work? If so I will reinstall and test again.

scmorrison commented 7 years ago

This would work:

{{#categories}}
<em>{{ title }}</em>
{{/categories}}
{{#category_pages}}
<li>{{ title }}</li>
{{/category_pages}}
evanmiller commented 7 years ago

category_pages should not be a top-level variable. It should remain an attribute of categories. I want to do something like:

categories:
  - title: General tasks
    category_pages:
      - page: compute/categories
      - page: compute/survival_times
      - page: summary/covariate_partition
      - page: tables/row_multipliers
  - title: Other tasks
    category_pages:
      - page: compute/duration
      - page: tables/delete
scmorrison commented 7 years ago

I understand what you are after now. I'll let you know when I have something working to test.

scmorrison commented 7 years ago

This should work now. But I did a bit of an overhaul on the way these are parsed so let me know if it has impacted any of your other variables. Also improved stability and error handling somewhat.

evanmiller commented 7 years ago

Hi, this is still not working as expected.

---
categories:
  - title: General tasks
  - category_pages:
    - page: compute/categories
    - page: compute/survival_times
    - page: summary/covariate_partition
    - page: tables/row_multipliers
---
       {{#categories}}
       <p><strong>{{ title }}</strong></p>
       <ul>
       {{#category_pages}}
           <li><a href="{{ layout.url_prefix }}{{ topic }}{{ layout.url_separator }}{{ anchor }}{{ layout.url_postfix }}">{{ title }}</a></li>
       {{/category_pages}}
       </ul>
       {{/categories}}

Output:

       <p><strong>General tasks</strong></p>
       <ul>
       </ul>
scmorrison commented 7 years ago

Hi @evanmiller, it seems to work for my tests. I tested with both of these structures:

---
categories:
  - title: General tasks
  - category_pages:
      - page: compute/categories
      - page: compute/survival_times
      - page: summary/covariate_partition
      - page: tables/row_multipliers
---

and

---
categories:
  - title: General tasks
    category_pages:
      - page: compute/categories
      - page: compute/survival_times
      - page: summary/covariate_partition
      - page: tables/row_multipliers
---

also, I upped the version to 0.2.2, can you confirm that this is the latest?

evanmiller commented 7 years ago

Ah, looks like I was creating two hashes on accident. It's working now. Thanks!

scmorrison commented 7 years ago

Excellent. Hope it helps with your site.

evanmiller commented 7 years ago
[master b284e28] Move link hierarchy to YAML
 2 files changed, 71 insertions(+), 121 deletions(-)

Much better :-D

scmorrison commented 7 years ago

That is great. Very cool to see that.