Closed gvwilson closed 2 years ago
There's no simple way, I'm afraid -- you'd have to use a filter to stop Ivy treating the .py
files as nodes, then handle copying them to the output directory yourself. Totally possible from an extension, but the easiest option is definitely to put them under res
.
Happy to give that a try (it's a good way to learn my way around some more of Ivy). What event should I listen for in order to prevent the conversion to HTML from taking place?
It's definitely very doable. Here's the filter you'll want to use:
https://github.com/dmulholl/ivy/blob/25b8ba3c69dd39d782ed1d496224af4a4629d124/ivy/nodes.py#L275
You can use it as a switch to decide if a file under src
should be loaded as a node. It gives you the pathlib.Path
object for the file, you can return True
to load it or False
to ignore it.
thanks - i've got it working. is there a central list somewhere of events that Ivy understands?
There isn't a list I'm afraid -- someday I'll get around to documenting them all!
If you're interested in experimenting with them you could add a print(hook)
call to the ivy.events.fire()
and ivy.filters.apply()
functions to trace them all triggering.
Ivy is basically a node-tree builder and a collection of hooks -- that makes it extremely flexible but also a little mysterious at first as the execution path isn't obvious.
Would you consider using an enum instead of strings to identify events? That would make it a lot easier to find 'em all (and possibly catch a few obvious-in-retrospect typos that I made).
Too late I'm afraid. Enums didn't exist in Python back when I built the mechanism and it would be a really big breaking change to switch to them now.
Good suggestion though and I'll definitely think about making the change if I'm ever going to bump the major version number.
I think it would be straightforward to accept either an enum element or the equivalent string and convert the latter to the former so that backward compatibility didn't break (?).
I'm building an extension to include snippets of code in HTML pages. I'd like to store the snippets in the same directories as the page files, i.e.,
src/a/index.md
will includesrc/a/one.py
,src/a/two.py
, and so on - it's easier to keep track of them this way than creatingres/a/one.py
,res/a/two.py
, and so on. If I try this right now, Ivy tries to templatizesrc/a/one.py
, which fails. Is there a way to tell it to copy some files belowsrc
rather than templatizing them (e.g., based on file extension)? Or should I put them underres
?