dmulholl / ark

A static website generator for people who enjoy the simpler things in life.
https://www.dmulholl.com/docs/ark/master/
The Unlicense
114 stars 7 forks source link

Q: how to generate a/index.html ? #5

Closed gvwilson closed 2 years ago

gvwilson commented 2 years ago

I have:

.
`-- src
    |-- a
    |   `-- index.html
    |-- b
    |   `-- index.html
    `-- index.html

I would like to produce:

.
`-- out
    |-- a
    |   `-- index.html
    |-- b
    |   `-- index.html
    `-- index.html

so that /a/ and /b/ will be valid URLs. Right now, Ivy wants to generate:

.
`-- src
    |-- a.html
    |-- b.html
    `-- index.html

Is there a way to force the desired behavior (so that old URLs won't break)?

dmulholl commented 2 years ago

Hi Greg. Ivy does indeed have a very-lightly documented option for generating directory-style URLs. If you add

extension = "/"

to your config.py file, that should do the trick.

gvwilson commented 2 years ago

Thank you - that's worked. On a similar note, is there a way to prevent generation of an index.html file for a node entirely? For example, if I have:

src
|-- advice
|   |-- findability.html
|   `-- safety.html
|-- bibliography.html
|-- index.html
`-- project.html

and I don't want either advice.html or advice/index.html in the output, can I achieve that? If I don't have src/advice/index.html, I get the error message:

Error: Ivy cannot locate a template file for the node: '@root/advice//'.
dmulholl commented 2 years ago

There's a build_node filter here that you can use as a switch to decide if a node should be written to disk.

You could write a little extension that checks the node's metadata for some kind of disable flag, e.g.

@ivy.filters.register('build_node')
def build_filter(enable_build: bool, node: Node):
    if node.get('disable'):
        return False
    return True

I have no idea where the template error is coming from though, Ivy should be perfectly happy with a node directory with no index file inside it.

dmulholl commented 2 years ago

I've actually gone ahead and added support for a disable flag directly to Ivy in version 6.1.0 as I think it's a generally useful feature.

gvwilson commented 2 years ago

thanks - I'll see if I can figure out why not having an index.whatever file in a directory is causing conniptions.

dmulholl commented 2 years ago

Definitely let me know if you can track that issue down any further!

dmulholl commented 2 years ago

I think we figured this one out :)

The template error was happening because Ivy always looks in the last resort for a template file called node.*. Your theme didn't have a template with this name.