sbrl / Pepperminty-Wiki

A wiki in a box
https://peppermint.mooncarrot.space/
Mozilla Public License 2.0
177 stars 20 forks source link

Feature Request: a careful reconcile process to update pageindex.json and recent-changes.json for externally modified files #242

Open kha84 opened 1 year ago

kha84 commented 1 year ago

I have a couple of use cases on my mind, where file-based wiki engine like PeppermintyWiki should shine, compared to other wiki engines. They are:

As far as I can see, PeppermintyWiki is heavily relying on a number of extra .json files. Some of them are acting as an cache (like idindex.json or statsindex.json). To my understanding such files can be easily dropped without loosing a bit of useful info, as they are recreated by wiki engine or from CLI console. Others are providing additional data or logs, like <Page Name>.comments.json which are holding page comments or recent-changes.json which is kept updated as you're updating pages. The pageindex.json is the most important file around here which holds info about what pages are there, mapping to the file name, what tags and revision they have.

As per my experiments, like I mentioned in my use cases above, it seems like for now it's enough to delete the pageindex.json, so it will be regenerated by wiki engine based on the actual files seen in the directory. This regeneration process even manages to pick up revisions, good stuff! But doing that delete means loosing tagging / dates / author information for all the pages that was stored in that file

Here I come to the essence of my feature request. I'd wish there was a better way of making PeppermintyWiki to know about external changes happened to its MD files. Some kind of update or reconcile process, which can be triggered from the web UI and CLI console. During that reconciliation, whatever inconsistencies are found between real-world files and pageindex.json are automatically resolved by making appropriate changes to pageindex.json:

It probably also makes sense to reflect all that in recent-changes.json as well to be consistent.

I can probably blow some dust off from my rusty PHP skills to make it happen, if you'll be willing to accept my pull request, once its done.

kha84 commented 1 year ago

I think I've nailed it. Will prepare a pull request for you to review

kha84 commented 1 year ago

It should also fix a bug current version is having: when you remove the pageindex.json file and you let PeppermintyWiki to regenerate it, if you have some of your md files in subfolders (like ./syntax/test.md.r0), the generated filenames for revisions were getting corrupted, because of inconsistent filename processing:

'filename' => 'ntax/test.md.r0',

instead of

'filename' => 'syntax/test.md.r0',

I have moved the filename processing code to become a new normalize_filename() function in 05-functions.php to reuse the same processing all the time, instead of different bespoke code which was scattered before