[TW5] TW as blog requires cookies - please help

133 views
Skip to first unread message

Mat

unread,
Jul 11, 2015, 7:15:47 AM7/11/15
to tiddl...@googlegroups.com
<hooking prelude> If you're a reader of TWaddle, there is a big problem.. for YOU! </hooking prelude>

...

In spite of my absence these past few weeks I've actually been pretty TW-active with my blog... or whatever it is... i.e TWaddle. No, nothing new there because I didn't publish it yet. I will, but there is a BIG problem: You can't tell which articles you've already read!

I continually tweak articles... edit spelling errors, add tags, insert links to new articles, etc. These tweaks typically don't justify re-reading the article. But tab Recent presents them as if they were the latest news.

This must actually be a problem for any application where "time sequencing" for external readers is important.

An option might be to sort lists by creation date but this is also not good because I write loads of articles that I don't finish right away. I tag these Unfinished and when I upload to the blog these are filtered out so they don't upload. However, this means that when they do eventually get finished and published, they would appear to be ancient.

I think what is needed is some cookie solution (right?)

The date for when the user reads (opens) the article could be logged and then a timeline could sort based on this ("if there is a read date, position it there, otherwise use edited date"). Maybe also a star/bookmark feature (another cookie) so an article sticks to list top or in some separate list.

Please help. Some cool stuff is coming your way.

<:-)

PMario

unread,
Jul 13, 2015, 9:51:49 AM7/13/15
to tiddl...@googlegroups.com
I think using cookies is a bad thing. we used cookies in TWClassik and they just caused problems. imo you could add a new field eg: publish and sort your own recent list. so if you think your changes are worh a new read, just change this field. if not, just don't update the field.

have fun!
mario

Eric Shulman

unread,
Jul 13, 2015, 1:36:51 PM7/13/15
to tiddl...@googlegroups.com
On Monday, July 13, 2015 at 6:51:49 AM UTC-7, PMario wrote:
I think using cookies is a bad thing. we used cookies in TWClassik and they just caused problems. imo you could add a new field eg: publish and sort your own recent list. so if you think your changes are worh a new read, just change this field. if not, just don't update the field. 

Cookies are a bad thing when they are being misused, but they still have their place...

In general, TW5 stores everything in tiddler fields, so that all stateful-ness can be saved with the document.  This provides much greater consistency and reliability of handling as compared to cookies.  However, in order for changed values to persist, it requires the ability to save the document, which most *visitors* to the published document won't have.

In addition, tiddler-based storage is not useful for tracking visitor-specific information, such as "when did this visitor last view this document" or "what was the last tiddler viewed by this visitor", etc.  This kind of information is different for each person who visits the page, and should *not* be saved with the document. Similarly, various option settings (e.g., story view (classic, zoomin, etc.), show/hide Sidebar) should be saved separately for each visitor, so that their desired display preferences could be automatically re-applied each time they visit the document.

To address this need for visitor-specific persistent information , I've implemented a "cookie binding" widget:

The widget syntax is:
   <$cookie name="..." tiddler="..." field="..." index="..."/>
where:
   name = the name of the cookie to store
   tiddler = the title of the tiddler containing the field/index value to track
   field = a fieldname within the tiddler
     or
   index = an attribute name within a DataTiddler

To create a cookie binding, add the <$cookie> widget to a tiddler tagged with $:/tags/PageTemplate.  When first rendered, the <$cookie> widgets will retrieve the saved cookie values (if any) and apply them to the corresponding tiddler fields/attributes.  From then on, any changes to the tiddler fields/attributes during the session are automatically pushed back to the cookie values, so they stay in sync with the current tiddler values.  When the document is closed *without saving*, the changed tiddler values are discarded, but the cookie values remain, so that they can be re-applied the next time the document is loaded.

To see this in action, just click on the "gear" icon in the upper right of the InsideTiddlyWiki document, and change some display settings (e.g., pick a different page background).  Then, reload the page, and see that your choices are automatically re-applied.  You can also use your browser's cookie management functions to directly view/edit/delete the cookies that were saved, and if you delete those cookies, and re-load the page you will see that the display settings revert back to the defaults that are saved in the document.

Note: there are also a few other widgets and macros for cookie handling:

* TWBook/Cookies/action-setcookie.js
   <$action-setcookie name="..." value="..."/>
   used with <$button> to explicitly set/clear a cookie value
   note: a blank value (i.e., value="") removes the cookie

TWBook/Cookies/getcookie.js
   <<getCookie name:"cookiename">>
   returns the value of the specified cookie
   use for direct display, or in filters, or in <$set>

TWBook/Cookies/cookienames.js
   <<cookienames>>
   primarily used with filters, returns the list of all cookie names for the current document

TWBook/Cookies/CookieJar
   declares <$cookie> bindings for settings ("OPT_*"), favorites ("FAV_*"), and Table of Contents "toggles" ("TOC_")
   note: this tiddler is tagged "$:/tags/PageTemplate so that the cookie widgets can use the TW core refresh cycle to continously "listen" for tiddler changes

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:

Mat

unread,
Jul 13, 2015, 6:43:30 PM7/13/15
to tiddl...@googlegroups.com
Thank you guys! I will probably go with both of your solutions! 

If I change my approach with tagging "Unfinished", to instead do as Mario suggests and add a publish date, this solves both what my "Unfinished" tag accomplishes and communicates information to the reader. Thanks Mario!

And if there's also cookie control... the reader could accumulate tiddlers he/she finds valuable and maybe even add his/her own annotations! In reading Erics kind explanation above and also http://www.w3schools.com/js/js_cookies.asp I'm thinking this might be possible.

For something like a blog (or a TW book!) this could be a (relatively) painless way for visitors to contribute feedback;

An "annotations editor" is toggled to show up (e.g on "hover" over a speech bubble image in tiddler toolbar)
The editor creates an annotations field for the current tiddler if the user types into it.
There is an aggregating tiddler, perhaps called Notes, listing the relevant tiddler titles and the annotations.
The possibility to accumulate the list over many sessions adds value as it would not have to be sent to the TW owner right away.

Sending it is, as usual, the hurdle. But with one accumulated list it is at least compact to handle. It could be exported into a static file or maybe just copy-pasted into a, on the TW, embedded form. BTW, is it possible to make the export feature export directly into memory? I.e so that the static file doesn't become a file but is just in the temporary memory to paste somewhere?

As someone in need of feedback I will play around with it.


Thanks again Mario and Eric!

<:-)


BJ

unread,
Jul 28, 2015, 4:27:58 AM7/28/15
to TiddlyWiki, elsd...@gmail.com
Hi Eric,
you are missing encoding the value before saving the cookie - so it breaks with content containing newlines etc.

cheers

bj

Also it is worth pointing out that cookies on  'file' urls do not work in chrome.
Reply all
Reply to author
Forward
0 new messages