Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
blocks:app-note:rss-feed [2024-03-14 09:29]
mattias [Installation]
blocks:app-note:rss-feed [2024-03-14 13:10] (current)
mattias
Line 1: Line 1:
 =====Use RSS in Blocks===== =====Use RSS in Blocks=====
  
-This application note exemplifies how to use a feed script to parse RSS feed and use child replication in blocks to publish the content on a spot.  +This application note assumes previous experience with blocks, it exemplifies how to use a feed script to parse an RSS feed and use child replication in blocks to publish the content on a spot.  
-[[https://www.rssboard.org/rss-specification| The RSS specification]] stipulates the basic rules for rss. One can tell from the content that the purpose of RSS was different before we had access to fast internet and networks. Now it is mainly used as source for news feeds but back then it was used to automatically download rich media such as video and imaged over night to allow us to see the latest news without having to download a video over a slow modem.  It is still a very useful method to provide feeds in a structured way.+[[https://www.rssboard.org/rss-specification| The RSS specification]] stipulates the scheme for rss. One can tell from the content of that site that the purpose of RSS has evolved over the years,  before fast internet and networks it was used to automatically download rich media such as video and imaged over night to allow us to see the latest news without having to download a video over a slow mode Now it is mainly used as source for news feeds but it is still a very useful method to provide feeds in a structured way. Some web CMS systems like in example WorldPress have built in functions to automatically publish its content in the form of rss. 
 ====Installation==== ====Installation====
  
-  * Make sure you have the latest script dependencies from https://github.com/pixilab/blocks-script installed+  * Make sure you have the latest script dependencies from https://github.com/pixilab/blocks-script merged in to the /script directory in the PIXILAB-Blocks-root[[blocks:drivers:tools#install_the_scripts|Instructions here]] 
-  * Copy the RSS.ts and _RSS.js from the script/feed-archive into script/feed+  * Enable the script by copying the RSS.ts and RSS.js from the script/feed-archive into script/feed directory. 
   * Restart blocks. This will enable the script and the script will write an example configuration file in scripts/files/   * Restart blocks. This will enable the script and the script will write an example configuration file in scripts/files/
-  * Rename the example file Rss.config.example.json to Rss.config.json +  * Rename the example file Rss.config.example.json to Rss.config.json (this file it written when the script is used) 
-  * Create a task with a do statement bound the the callable Script.feed.RSS.reInitialize +  * Create a task with a do statement bound the scripts Script.feed.RSS.reInitialize callable. 
-  * Run the task to consider the latest settings. +  * Run the task to restart the script and use the sample settings. 
   * Download the example block from here: {{ :blocks:app-note:rss:rss_block.zip |}}   * Download the example block from here: {{ :blocks:app-note:rss:rss_block.zip |}}
-  * Import the example block into the editor using the import feature in the editor. +  * Import the example block into the editor using the Block/Import ZIP file feature in the editor.  
 +  * Test by open the block in for editing and use the Edit/Show editor preview feature. 
 + 
 +You should expect something like this in the preview:  
 +{{:blocks:app-note:rss:rssblock.png?600|}} 
 + 
 +:!: Please note, if working with feeds on spots, it is the spot that downloads any images, not the server, hence the spot must be able to access any images.  
  
  
Line 22: Line 30:
 ====The example block==== ====The example block====
  
-The example block uses child replication to replicate one slide per feed item in a slideshow.  It also exposes the RSS channel image and channel title in the content. Please study the block and its bindings to get full understanding. +The example block uses child replication to replicate one slide per feed item in a slideshow.  It also exposes the RSS channel image and channel title in the content. Please study the block and its bindings to get the full understanding. 
  
-The block uses a spot parameter named //feed// to parametrize the property paths to accomodate the use of multiple feeds exposed by the feed script. That way we can create a single block that can show different feeds depending on what spot it is loaded to by setting up that parameter and give it the value that matched the feed we want to use on that spot. +The block uses a spot parameter named //feed// to parametrize the property paths to accomodate selection from multiple feeds exposed by the feed script. That way we can create a single block that can show different feeds depending on what spot it is loaded to by setting up that parameter and give it the value that matched the feed we want to use on that spot. 
  
 If no such parameter has been configured on the spot itself with a value it will fall back to the //Formal Value// used in the block itself : If no such parameter has been configured on the spot itself with a value it will fall back to the //Formal Value// used in the block itself :
Line 35: Line 43:
 ====Configure the script==== ====Configure the script====
 ===Configuration file=== ===Configuration file===
-This feedscript can use configuration file //Rss.config.json// that is stored in /script/files/, the script generate an exampe file //Rss.config.example.json// that can be renamed and used as an example. The text must be valid JSON.+This feedscript can use an optional configuration file //Rss.config.json// stored in /script/files/, the script generates an exampe file //Rss.config.example.json// that can be renamed and used as a template. The text must be valid JSON format.
  
 In the example configuration we can see an entry where a preferred image size has been indicated. This setting only works for feeds that contain what's in RSS called a <media:group> containing several <media:content> because such groups can only contain different versions of the same image according to the RSS standard. The script will find the image that has the best matched the wanted size. In the example configuration we can see an entry where a preferred image size has been indicated. This setting only works for feeds that contain what's in RSS called a <media:group> containing several <media:content> because such groups can only contain different versions of the same image according to the RSS standard. The script will find the image that has the best matched the wanted size.
-Use the //maxAge// to control for how long we want to show the article in the feed, and use the maxLength  to limit how many articles to show from the feed.  The latter can be also be controlled in the block child replication //Skip// and //Limit// settings.+Use the //maxAge// to control for how long we want to show the article in the feed, and use the maxLength  to limit how many articles to show from the feed.  The latter can also be controlled in the block child replication //Skip// and //Limit// settings.
  
 Exampel configuration: Exampel configuration:
Line 67: Line 75:
  
  
-===Configure with task===+===Configure feeds with tasks===
  
-As an option configure feeds in runtime using a callable on the script as in this example:+Feeds can be configured in runtime using a callable on the script as in this example:
  
 {{:blocks:app-note:rss:rsscallable.png?600|}} {{:blocks:app-note:rss:rsscallable.png?600|}}
  
-The options are basically the same but will only be added if a task has been setup to be triggered at startup if in a production setup+The options are basically the same as with the config file method, but feeds will only be added if a config task has been setup to be triggered at startup. 
-If using task to configure feeds one may want to remove the config file.+If using the task to configure feeds one may want to remove the config file if present.
  
 ===Reinitialize the script=== ===Reinitialize the script===
  
-The feed script exposes a second callable that merely reset the script, removes any run-time added feeds and read the configure file again. +The feed script exposes a second callable that merely resets the script, removes any run-time added feeds and reads the configure file again if present
  
 ====Styling==== ====Styling====
-In the example block we use a CSS trick to be able to add ellipsis [...] to indicate that we cannot show all text available from the feed. It is a bit tricky to use because one must also limit the text-block manually in the way that it is just capable to show as many lines as specified in the css, else the line with the ellipsis will appear on the correct line but lines can still appear after the ellipsis. +In the example block we use a CSS trick to be able to add ellipses [...] to indicate that we cannot show the full text available from the feed items description. It is a bit tricky to use because one must also limit the text-block manually in the way that it is just capable to show as many lines as specified in the css rule, else the line with the ellipsis will appear on the correct line but lines can still appear after the ellipsis. 
-The ellipsis css rule:+The ellipsis css rule used here:
 <code> <code>
 .rss .multi-line-ellipsis { .rss .multi-line-ellipsis {
Line 90: Line 98:
 } }
 </code> </code>
 +