Source code - Fluid Topics - Latest

Fluid Topics Designer Guide

Category
Reference Guides
Audience
public
Version
Latest

The following example relies on the Result variable (contains information about the current search result).

To add the same Custom component:

  1. In the HTML panel, copy and paste the following:

    <div id="type"></div>
    
  2. In the JS panel, copy and paste the following:

    const type = result.type;
    var metadata;
    switch (type) {
      case "MAP":
        metadata = result.map.metadata;
        break;
      case "TOPIC":
        metadata = result.topic.metadata;
        break;
      case "DOCUMENT":
        metadata = result.document.metadata;
        break;
    }
    
    var lastEdition;
    metadata.forEach(function (element) {
      const key = element.key;
      if (key === "ft:lastEdition") {
        lastEdition = element.values[0];
      }
    });
    
    const date = new Date(lastEdition);
    const now = Date.now();
    const nbDays = (now - date) / (1000 * 3600 * 24);
    if (nbDays < 10) {
      document.getElementById("type").innerHTML = `
        <ft-chip highlighted dense icon="STAR_PLAIN" iconvariant="fluid-topics">
          New
        </ft-chip>
      `;
    }
    

    The <ft-chip> element can use the same icons available in the Icon component.

  3. Save the component.

  4. Save and publish the page.