picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

assets_dir: Ignored in config.yml #596

Closed JoshuaPettus closed 2 years ago

JoshuaPettus commented 2 years ago

Hi here are the specs of the server I'm using Ubuntu 2004 Nginx 1.21.1 PHP 8.0.9 picocms 2.1.4

I was originally using the nextcloud plugin version of pico cms but the additional restrictions and security wasn't meeting my needs so I setup picocms as a standalone on its own subdomain.

I've installed picocms in /var/www/pico

But the thing is, I want to continue using nextcloud as a frontend for editing the website. I managed to point content_dir at the content directory in my nextcloud files which works nicely. But when I point assets_dir to the assets directory in my files, the images stored there do not display on my site.

here is the configuration

content_dir: /var/server/nextcloud/data/me/files/www/content assets_dir: /var/server/nextcloud/data/me/files/www/assets

A bit of troubleshooting and I've determined that even though assets_dir is set in the config.yml, The /var/www/pico/assets directory is actually still in play. The images show up on my site just fine when I copy the images there.

This is not ideal as I'd like to fully modify the site without having to ssh to the server.

Thank you!

PhrozenByte commented 2 years ago

You must somehow publish your assets dir with your webserver, otherwise a browser won't be able to access the resources. There are various solutions for this:

  1. Publish /var/server/nextcloud/data/me/files/www/assets below a virtual directory. If you're using Apache, refer to the Alias directive.
  2. Reverse the setup: Don't let Pico access the files below /var/server/nextcloud, but Nextcloud access the files below /var/www/pico: Use Nextcloud's files_external app to include arbitrary local paths (i.e. /var/www/pico/content and /var/www/pico/assets) in your Nextcloud.
  3. Symlink /var/www/pico/assets to /var/server/nextcloud/data/me/files/www/assets and unset the assets_dir config. You can even do the same with the content dir.
mayamcdougall commented 2 years ago

Personally, I prefer symlinks approach for simplicity. 😜

Just make sure the original files live in Nextcloud, because it won't play as nice with the symlinks when it's time to sync your files (if I remember correctly). And definitely do the same for your content folder.

I just wanted to chime in and add an explanation of why this was happening to you. Also, I was already thinking about it before @PhrozenByte responded, lol.

As far as I know, Pico doesn't actually use the assets_dir property for anything other than replacing the %assets_url% placeholder. With the content_dir, you're actually pointing Pico at a different location to look for files. These files are processed by Pico to make the pages, but they're not accessible through your web server at /content, so it really didn't matter that they were somewhere else.

Your assets on the other hand are handled directly by the web server and not Pico. The %assets_url% placeholder just provides a convenient substitute for the url, it doesn't actually provide access to the files. So, when you did this, it was either trying to point to /var/www/pico/var/server/nextcloud/data/me/files/www/assets, if you were using %assets_url%, which didn't exist, or just to an empty /var/www/pico/assets if you were typing the URL in your markdown files manually.

JoshuaPettus commented 2 years ago

Ah! That makes total sense! Thanks guys! Unfortunately it seems a little unintuitve. I expected assets_dir would be the same as content_dir in how it works. Perhaps it should be renamed assets_url? or just not be there as it seems to just be a newb trap? What would be a use case for it?

I thought to try the symlink approach before I went down this config file rabbit hole, but I had some weird unexpected result. I did "ln -s /var/server/nextcloud/data/me/files/www/assets /var/www/pico" and the symlink came up broken. Both the source directory and destination are owned by www-data...so beats me. I'll get to the bottom of it. Most likely something stupid...

The other two ideas sound good too, I may give them a try.

[Edit] Yeah the simlink method works just fine. Beats me what I was doing wrong.

PhrozenByte commented 2 years ago

Perhaps it should be renamed assets_url?

There's also a assets_url config :wink: Both assets_dir and assets_url are required config variables, they describe different things, even though Pico can often simply guess them from one another.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: