Aggregating images for a spotlight gallery by RegEx and http-Request

Hi,
I would like to use @saqimtiaz’ elegant spotlight-plugin to build different kinds of galleries.

One tpye of gallery shall be created using the images of a tiddler like in this example. The specific challenge is, that the images in my wiki images are shown by a custom macro of the form: <<pic “source” “caption”>> I use this to apply conditional styles and to use a sidebar-tab to compare to images.
Is it possible to aggregate this sort of gallery by a RegEx-Filter?

The other galleries, I would like to display, would be aggregated by the images in a folder on my server.
I have not succeeded in using the new HTTP-request feature yet.
How can I use it to build get all image files in a folder? Do have to put a PHP into the folder, to create a response?

Thanks for your help.

Try using the _images operator with the all suffix.

[<current tiddler>_images:all[]]

With this suffix the operator wikifies the tiddler and attempts to extract all images.

I assume your folder is being served by a HTTP server? If it provides a directly listing that could be fetched and parsed. Otherwise you need some code on the server that can respond to an HTTP request and return a list of images.

2 Likes

How can I find that out? What is the easy spell to get the listing of a folder?

Is your code on a server, or are you using some software on your local machine to act as a server? What operating system?

If you’re using this on a normal everyday use computing device and not a server, you will need some additional software and configuration to create a server to respond to HTTP requests

1 Like

My gallery-folder would be on a real server.

Your automatic gallery from tiddler-images works really great now - even with the images in my macros. Could I make a template where this automatically works on every tiddler - because I would like to have this work on every tiddler?

Yes. I would suggest cloning the default View Template under a different name, wrapping the code around it, and introducing it via the cascade.

Assuming your images are in a folder on your server at myserver.com/images/, does visiting that URL show a list of files?

So far it shows “access not allowed”
How should a response look like and should it be generated by php?

How to generate the response really depends on the server in question and which other services you have running. PHP if available would be an option.

I recommend returning the list of images in the folder as an array in JSON. Consider whether you also want to return further information about each image, such as size or last modified date.

It will take me some time to dive into php to build this. I think the most elegant way would be to have one php in the mother-directory which serves for all subfolders.

The much more urgent question for me is how to get the automatic gallery function for every tiddler without having to put an eventcatcher into each one. Do you think there is a way to do this without altering any core-tiddlers?

Perhaps you could enhance your plugin and create a controlpanel to configure this. But I think most users would choose this behaviour and this would really promote your widget.

Hello @saqimtiaz , I still have not suceeded in implementing your gallery in a way that every tiddler creates creates a gallery for the images automatically.
I even could not get it to work using buttons within my macro which of course is less elegant than working with an eventcatcher like in your version.

Do you think there is a way to do this with an eventcatcher in every tiddler without altering core-tiddlers?

Have you attempted this approach?

1 Like
  1. $:/config/ViewTemplateBodyFilters/spotlight
    tagged $:/tags/ViewTemplateTitleFilter
[search[<pic]] [search[<pic]] +[limit[1]then[$:/plugins/spotlight/ViewTemplate/body]]
  1. $:/plugins/spotlight/ViewTemplate/body
\import [all[shadows+tiddlers]tag[$:/tags/Macro/View/Body]!is[draft]] [all[shadows+tiddlers]tag[$:/tags/Global/View/Body]!is[draft]]
\procedure spotlight-actions()
<$action-spotlight
	$images={{{ [<storyTiddler>_images[]format:titlelist[]join[ ]] }}}
	$start=<<dom-src>>
/>

\end

<$reveal tag="div" class="tc-tiddler-body" type="nomatch" stateTitle=<<folded-state>> text="hide" retain="yes" animate="yes">
<$eventcatcher $click=<<spotlight-actions>> selector="img" class="spotlight-mixmedia-example">

<$transclude tiddler={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/ViewTemplateBodyFilter]!is[draft]get[text]] :and[!is[blank]else[$:/core/ui/ViewTemplate/body/default]] }}} />

</$eventcatcher>
</$reveal>

Well is this how it should work? It’s my first attempt to the cascade-mechanism

Perhaps try something a little bit simpler:

\procedure spotlight-actions()
<$action-spotlight
	$images={{{ [<storyTiddler>_images:all[]format:titlelist[]join[ ]] }}}
	$start=<<dom-src>>
/>
\end

<$eventcatcher $click=<<spotlight-actions>> selector="img">

<$transclude tiddler="$:/core/ui/ViewTemplate/body/default" />

</$eventcatcher>

2 posts were split to a new topic: Spotlight plugin: Markdown format support?

Thank you @saqimtiaz, but this does not work yet in my TW.
Does the tiddler need a specific tag? I would guess no. Tagging it viewtemplate resulted in a double-body.

I guess there is something wrong with my cascade config… could I use your image filter to build a better one?

Another question: Is it useful to put procedure into a global macro. And could I use a config-tiddler to determine wheter the spotlight just shows the image, or all images in the tiddler or even all images in the storyriver.

If this was possible I would build a controlpanel.

I suggest just using this template instead of the default whenever no other cascade matches. To do so, the cascade tiddler would look like this:

[[$:/plugins/spotlight/ViewTemplate/body]]

with a list-before field with value: $:/config/ViewTemplateBodyFilters/default

You absolutely can. You just need to rewrite the procedure to respect the config tiddler and pass a different list of images to the $action-spotlight accordingly. The spotlight widget just needs two parameters, a list of all the images and the current image.

With many long tiddlers open in the story at the same time, retrieving images for all of them via wikification might be slow, you will need to test and see if there are any issues. The filter was designed to be able to extract images from tiddlers without them needing to be in the story. For tiddlers in the story more efficient filters could be written.

1 Like

autospotlight not working.json (781 Bytes)
I still do not get this to work…here are the two tiddlers

1 Like

You need to correct the tag on the cascade tiddler to $:/tags/ViewTemplateBodyFilter and the list-before field needs to be $:/config/ViewTemplateBodyFilters/default

1 Like

yeah…great. Thank you so much!
Here is the bundle for those who are interested: autospotlightworking.json (776 Bytes)