-
Notifications
You must be signed in to change notification settings - Fork 49
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
Handle static files outside the templates folder #58
Comments
Can you be more descriptive? If I understand correctly, using |
it says everywhere in the docu, that the |
You're right @maxxst, writing |
Oops didn't fully understand the issue when I looked at this earlier. Admittedly, I actually haven't used the staticfiles feature in my sites, so I'm a little hazy on how they work. @dominicrodger was the one who introduced them, in 4130fbb. My understanding is that this feature is for when users are building their site into a "build" directory, or for when they need to avoid compilation (because perhaps they're Javascript uses brackets {{}}). @dominicrodger, is there a reason we're searching for static files in In any case, @maxxst, if you are just building to a "build" directory, I can confirm @tmewett's solution does work. |
I think I did it that way because it seemed to make sense for to look on |
Okay cool. I'll implement a fix for this this week. Unfortunately, seems the change will be backward incompatible. |
Actually, thinking about this more, I think handling static files it outside the scope of this project. I'm going to deprecate that feature. It's trivial to use Make to copy static files over. I want staticjinja to only deal with handling Jinja templates. |
Sorry to open this back up, but I possibly have an argument for why staticjinja should be able to handle static files: I want my website src directory to directly mirror the build directory. For example
should lead to a build/ directory that exactly mirrors src/ except that templates are rendered. In other words, I don't want to have to use a templates/ directory separately from static css/ and img/ directories for two reasons:
Also, I would argue that requiring people to use Make is just another hurdle, I would envision the point of staticjinja to be a one-stop-shop for making a simple website in plain python. I have a PR request incoming that adds better static/partial/ignored/template filtering, I'll try yo remember to link that here when complete. |
Re-opening this, because I think this still is a useful feature. This opinion is also supported by the [as of now] three 👍 's that my previous comment received. As I look into supporting copying static files, here are some of my initial design requirements/brain dump:
Please give any feedback or suggestions that you have. Thanks! |
Update 2022-07-08OK, so I actually wrote a Makefile to replicate / restore the staticjinja functionality for static files. It does not have a lot of prerequisites and it is as easy to use as the
Prerequisites
Usage The interface is similiar to the
The Makefile This code should be copied to a file named srcpath = ./templates
outpath = ./
statpath =
export SRCPATH=$(srcpath:/=)/
export OUTPATH=$(outpath:/=)/
export STATPATH=$(statpath:/=)/
MAKEFLAGS += -j2
build: .build_srcpath .build_statpath
.build_srcpath:
@staticjinja build --srcpath="$${SRCPATH}" --outpath="$${OUTPATH}"
.build_statpath:
@if [ -n "$${STATPATH%/}" ]; then \
echo "Copying static content..."; \
cp -r "$${STATPATH}"* "$${OUTPATH}" 2>/dev/null; \
fi
watch: .watch_srcpath .watch_statpath
.watch_srcpath:
@staticjinja watch --srcpath="$${SRCPATH}" --outpath="$${OUTPATH}"
.watch_statpath: .build_statpath
@if [ -n "$${STATPATH%/}" ]; then \
echo "Watching '$$(realpath "$${STATPATH}")' for static content changes..."; \
inotifywait -mrq -e create,modify,moved_to "$${STATPATH}" | while read FILEPATH EVENT FILE; do \
RELFILEPATH="$${FILEPATH##"$${STATPATH}"}"; \
RELFILE="$${RELFILEPATH}$${FILE}"; \
echo "STATIC CONTENT $${EVENT} $${RELFILE}"; \
echo "Copying static content $${RELFILE}..."; \
mkdir -p "$${OUTPATH}$${RELFILEPATH}"; \
cp -r "$${STATPATH}$${RELFILE}" "$${OUTPATH}$${RELFILE}" 2>/dev/null; \
done; \
fi Also, even though this approach works and is not too horrible, having this functionality right in staticjinja would make things a lot easier. Original postI think Make is an inappropriate solution for this problem, for several reasons:
This is exactly what I would expect from staticjinja (and what staticjinja actually did before the depreciation): building a whole website by executing one command. For example I could just call Now, this functionality could be imitated by using a Makefile to call But what is even worse is that So, at the moment, all staticjinja allows is to continuously monitor template changes, while the monitoring of static files is left as an exercise. This is somewhat disappointing, at least if one saw staticjinja as a way to render a website (as opposed to just the HTML part of a website). If I am mistaken and the previous functionality can actually be replicated using a Makefile: Would it be possible to add an example Makefile to the documentation? I think this is a common problem / task which would warrant to do so. |
Right now I have a folder structure like that :
I would be so happy if I could include
css/
andimg/
to the static pathThe text was updated successfully, but these errors were encountered: