Class StoryblokLoaderTask

java.lang.Object
com.mohamnag.jstatic.plugins.storyblok_loader.StoryblokLoaderTask
All Implemented Interfaces:
BuildTask

public class StoryblokLoaderTask extends Object implements BuildTask
This loads the list of stories from Storyblok API, puts full data under the key "storyblok" in root node. It also creates one page per story in data tree under the node defined by StoryblokLoaderConfig.KEY_TARGET_NODE.

To determine the path of the page, we use the full slug of the page and will append `/index` to it if it is not already containing it. This is in sync with what Storyblok's UI is expecting from the relation between slug and paths. This means if you want to put a page on root of its directory you either define it as such in the editor or use the slug index for it if not possible.

If you are using links to internal stories, you need to get the id in your link object and lookup the URL from the root level links list of the full data object that is put under root node. If using Hamcrest templates, probably having a helper to do this would be the easiest solution. Something between the lines of:

    Handlebars.registerHelper(
     'resolveStoryblokLinkUrl', function (page, link) {
         let storyblokData = page.getRecursiveData('storyblok').orElse(undefined);
         if (storyblokData) {
             for (const key in storyblokData.links) {
                 let linkData = storyblokData.links[key];
                 if (linkData.uuid === link.id) {
                     return linkData.url;
                 }
             }
         }

         return "";
     });
   
See Storyblok documentation for details on how links work.

See StoryblokLoaderConfig for configuration.

  • Constructor Details

    • StoryblokLoaderTask

      public StoryblokLoaderTask(Config globalConfig)
  • Method Details

    • run

      public void run(BuildContext buildContext)
      Specified by:
      run in interface BuildTask
    • underWatchInputPaths

      public List<Path> underWatchInputPaths()
      Description copied from interface: BuildTask
      If a plugin depends on file input, it shall return list of its input paths to be watched for changes. Paths can be either files or directories. In case of directories, only root path are necessary to be listed and if input path has subdirectories, they will be automatically watched.
      Specified by:
      underWatchInputPaths in interface BuildTask
    • underWatchConfigPaths

      public List<Path> underWatchConfigPaths()
      Description copied from interface: BuildTask
      If a plugin depends on config files in addition to the general config file of the application, like functionality extensions stored in files, it shall return these paths here. A change detected in these paths will result in recreation of the plugin.
      Specified by:
      underWatchConfigPaths in interface BuildTask