TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
7.97k stars 1.18k forks source link

[BUG] The publishFilter Deletes System Tiddlers If They Appear in Filter #7414

Closed kookma closed 1 year ago

kookma commented 1 year ago

Describe the bug

Using global publishFilter when building index.html removes system tiddlers from TiddlyWiki if they appear in the publishFilter

Expected behavior

The building process when using publishFilter contains system tiddlers should not touch the tiddlers in the TiddlyWiki (server, e.g test in the below example) itself.

To Reproduce

  1. create a new wiki called test : tiddlywiki test --init server

  2. launch wiki tiddlywiki test --listen

  3. create some tiddlers

  4. create a $:/config/PublishFilter tiddler tagged with $:/tags/Macro with below content

    \define publishFilter()
    -[[Test 201]]
    -[[Test 400]]
    -[[$:/somepath/test]]
    -[list[$:/somepath/test]]
    \end
  5. build index tiddlywiki test --build index

  6. refresh the wiki by pressing F5 or stop and restart the server

  7. Problem: the $:/somepath/test] is removed from TiddlyWiki (server e.g. test here)

I repeated the test any tiddler with $:/ if appears in publishFilter will be removed from the server itself.

Screenshots

No response

TiddlyWiki Configuration

Desktop (please complete the following information):

Additional context

This is part of tiddlywiki.info in test wikifolder

    "build": {
        "index": [
            "--render",
            "$:/plugins/tiddlywiki/tiddlyweb/save/offline",
            "index.html",
            "text/plain"
        ],
pmario commented 1 year ago

May be because of this: -[list[$:/somepath/test]] does not produce the expected output

image

Jermolene commented 1 year ago

Hi @kookma what's going on here is that the publish filter is applied when building the index.html file for the browser. Then when the index.html file is loaded, the sync process notices that there are tiddlers on the server that don't exist in the browser. It assumes that those tiddlers have been deleted in the browser, and so tries to delete those tiddlers from the server to sync things.

As you have found, the publish filter isn't really intended to be used with the client/server synchronisation. What are you trying to accomplish?

pmario commented 1 year ago

May be instead of removing content, that you do not want to publish you may create a new "render-template" similar to the "$:/plugins/tiddlywiki/tiddlyweb/save/offline" template which contains the stuff you want to publish ... just an idea

kookma commented 1 year ago

Thank you @Jermolene I have created several editions and publish single html TiddlyWiki files using the build command.

There are some tiddlers only needed when I use the editions on Node JS

I use publishFilter to remove them from index.html

Jermolene commented 1 year ago

Hi @kookma the render command allows variables to be set from the command line, so you don't need to include the definition of publishFilter within the wiki itself. For example:

    "build": {
        "index": [
            "--render",
            "$:/plugins/tiddlywiki/tiddlyweb/save/offline",
            "index.html",
            "text/plain",
            "",
            "publishFilter",
            "-[[Test 201]] -[[Test 400]] -[[$:/somepath/test]] -[list[$:/somepath/test]]"
        ],
kookma commented 1 year ago

Thank you, Jeremy! Your solution works.

Further observations: (Updated: 2023.04.24)

  1. strangely only system tiddlers are removed from server! In my original example $:/somepath/test is removed
  2. even I use two different browsers e.g. Edge for development and Firefox for working with the produced index.html still the problem is there and TW deletes $:/somepath/test when I use publishFilter.
  3. As a habit with single file, I press F5 and refresh the window! I noticed if I do not refresh, the tiddler won't be deleted!

Should I close this issue or leave it open?

kookma commented 1 year ago

I use your solution in tiddlywiki.info

 "build": {
         "index": [
             "--render",
             "$:/plugins/tiddlywiki/tiddlyweb/save/offline",
             "index.html",
             "text/plain",
             "",
             "publishFilter",
             "-[[Test 201]] -[[Test 400]] -[[$:/somepath/test]] -[list[$:/somepath/test]]"
         ],

It works great! I created a global macro called singleFileExclusion and modified above command as below

             "",
             "publishFilter",
             "-[subfilter<singleFileExclusion>]"

The singleFileExclusion contains filter expression of all tiddlers/plugins to be excluded from publishing with single index.html

pmario commented 1 year ago

@kookma ... Since the issue is resolved. Can we close it? ...

IMO your last post / solution would make a good example for a new tiddler eg: PublishFilter tagged Mechanisms at tw-docs

https://tiddlywiki.com/#Mechanisms:Mechanisms%20SavingMechanism

kookma commented 1 year ago

Hi Mario, Sure I will submit a PR and explain this to be included in documentation (target tw5.com)