New Shortcut

For the PWA feature we added 1 new shortcut.

{{ layout | slug | field }}

Which will return the URL for a specific layout's field. Field must be one of : 

  • js
  • js_vendor
  • css
  • css_vendor

So by example {{ layout | home | js }} will render /en/338/js/_bSBAAvG---.js

New Option for Riot shortcut

We also needed a way to get the tag's URL to add it to the FILES_CACHE variable in our service worker. We need this option because the URLs are dynamic and use the _rev attribute of the document.

{{ riot | demo | url }}

This script will return the URL of the desired tag.

For your information, here the code added in the concerns.moon file :

--  
-- return from Layout's field
-- slug is layout's slug
-- fields are : js, css, js_vendor, css_vendor
if action == 'layout'
  request = 'FOR layout IN layouts FILTER layout.name == @slug RETURN layout'
  object = aql(db_name, request, { slug: item })[1]
  if object
    jshmac = stringy.split(encode_with_secret(object.i_js, ''), ".")[2]\gsub("/", "-")
    csshmac = stringy.split(encode_with_secret(object.i_css, ''), ".")[2]\gsub("/", "-")
    output = "/#{params.lang}/#{object._key}/vendors/#{jshmac}.js" if dataset == 'js_vendor'
    output = "/#{params.lang}/#{object._key}/js/#{object._rev}.js" if dataset == 'js'
    output = "/#{params.lang}/#{object._key}/vendors/#{csshmac}.css" if dataset == 'css_vendor'
    output = "/#{params.lang}/#{object._key}/css/#{object._rev}.css" if dataset == 'css'
  else output = ' '

Leave a comment