<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Blog search in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Blog-search/m-p/641716#M28925</link>
    <description>&lt;P&gt;Gabriel messaged me directly but to help others, I think searching on keyup would work e.g.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const input = document.getElementById('blog-search-input');
input.onkeyup = (e) =&amp;gt; {
  let input_val = this.value;
  const listSelector = documents.getElementsByClassName('blog-listing-wrapper')[0]; // whatever div wraps your blog listings

  if (input_val.length &amp;gt; 0) {
    let request = new XMLHttpRequest();
    request.open('GET', "https://api.hubapi.com/contentsearch/v2/search?portalId=[PORTAL ID]&amp;amp;term="+input_val+"&amp;amp;type=BLOG_POST&amp;amp;length=SHORT", true);

    request.onload = function() {
      if (this.status &amp;gt;= 200 &amp;amp;&amp;amp; this.status &amp;lt; 400) {
        // Success!
        let data = JSON.parse(this.response);
        let results = data.results;
        let amount = results.length;
        if (results === undefined || results.length == 0) { 
          listSelector.innerHTML = "";
          listSelector.innerHTML += "&amp;lt;p style='margin: 0 auto;'&amp;gt;Sorry, there are no results for that search. Please search something else.&amp;lt;/p&amp;gt;"
        } else {
          results = Array.from(results);
          results.forEach(node =&amp;gt; {
            let date = node.publishedDate;
            let tag = node.tags[0];
            // structure this html for each result however you structure your blog listings normally
            listSelector.innerHTML += "&amp;lt;div class='post-item content-item'&amp;gt;&amp;lt;div class='img-wrapper mb-20 blog-featured-image-wrapper blog-search-image'&amp;gt;&amp;lt;a href="+ node.url + " class='hs-featured-image-link'&amp;gt;&amp;lt;img src="+ node.featuredImageUrl + "&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;p id='hubspot-topic_data'&amp;gt;" + tag + "&amp;lt;/a&amp;gt;&amp;amp;nbsp;|&amp;amp;nbsp;&amp;amp;nbsp;" + date + "&amp;lt;/p&amp;gt;&amp;lt;div class='post-header blog-title'&amp;gt;&amp;lt;h3 class='h5'&amp;gt;&amp;lt;a href="+ node.url + " &amp;gt;"+ node.title + "&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class=' blog-body clearfix'&amp;gt;&amp;lt;p&amp;gt;"+ node.description + "&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;"
          });
        } 
      } else {
        // We reached our target server, but it returned an error
        console.log(this.response);
        listSelector.innerHTML = "";
        listSelector.innerHTML += "&amp;lt;p style='margin: 0 auto;'&amp;gt;Sorry, there was an error&amp;lt;/p&amp;gt;"
      }
    };

    request.onerror = function(status, error) {
      console.log(error);
    };

    request.send();
  }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 31 May 2022 09:33:50 GMT</pubDate>
    <dc:creator>piersg</dc:creator>
    <dc:date>2022-05-31T09:33:50Z</dc:date>
    <item>
      <title>Blog search</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Blog-search/m-p/641040#M28907</link>
      <description>&lt;P&gt;Hello, I'm trying to figure out how this blog search might be put together:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.safebreach.com/resources/blog/" target="_blank"&gt;https://www.safebreach.com/resources/blog/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Basically, after typing your search query, the blog index page should display the articles including the search query.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 07:30:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Blog-search/m-p/641040#M28907</guid>
      <dc:creator>GabrielPerte</dc:creator>
      <dc:date>2022-05-30T07:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Blog search</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Blog-search/m-p/641198#M28911</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/181999"&gt;@GabrielPerte&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this can be done via AJAX. So basically you'll need to clone and modify the search module. I think&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/103660"&gt;@piersg&lt;/a&gt;&amp;nbsp;has done something like that in the past&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anton&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 12:48:28 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Blog-search/m-p/641198#M28911</guid>
      <dc:creator>Anton</dc:creator>
      <dc:date>2022-05-30T12:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Blog search</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Blog-search/m-p/641716#M28925</link>
      <description>&lt;P&gt;Gabriel messaged me directly but to help others, I think searching on keyup would work e.g.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const input = document.getElementById('blog-search-input');
input.onkeyup = (e) =&amp;gt; {
  let input_val = this.value;
  const listSelector = documents.getElementsByClassName('blog-listing-wrapper')[0]; // whatever div wraps your blog listings

  if (input_val.length &amp;gt; 0) {
    let request = new XMLHttpRequest();
    request.open('GET', "https://api.hubapi.com/contentsearch/v2/search?portalId=[PORTAL ID]&amp;amp;term="+input_val+"&amp;amp;type=BLOG_POST&amp;amp;length=SHORT", true);

    request.onload = function() {
      if (this.status &amp;gt;= 200 &amp;amp;&amp;amp; this.status &amp;lt; 400) {
        // Success!
        let data = JSON.parse(this.response);
        let results = data.results;
        let amount = results.length;
        if (results === undefined || results.length == 0) { 
          listSelector.innerHTML = "";
          listSelector.innerHTML += "&amp;lt;p style='margin: 0 auto;'&amp;gt;Sorry, there are no results for that search. Please search something else.&amp;lt;/p&amp;gt;"
        } else {
          results = Array.from(results);
          results.forEach(node =&amp;gt; {
            let date = node.publishedDate;
            let tag = node.tags[0];
            // structure this html for each result however you structure your blog listings normally
            listSelector.innerHTML += "&amp;lt;div class='post-item content-item'&amp;gt;&amp;lt;div class='img-wrapper mb-20 blog-featured-image-wrapper blog-search-image'&amp;gt;&amp;lt;a href="+ node.url + " class='hs-featured-image-link'&amp;gt;&amp;lt;img src="+ node.featuredImageUrl + "&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;p id='hubspot-topic_data'&amp;gt;" + tag + "&amp;lt;/a&amp;gt;&amp;amp;nbsp;|&amp;amp;nbsp;&amp;amp;nbsp;" + date + "&amp;lt;/p&amp;gt;&amp;lt;div class='post-header blog-title'&amp;gt;&amp;lt;h3 class='h5'&amp;gt;&amp;lt;a href="+ node.url + " &amp;gt;"+ node.title + "&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class=' blog-body clearfix'&amp;gt;&amp;lt;p&amp;gt;"+ node.description + "&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;"
          });
        } 
      } else {
        // We reached our target server, but it returned an error
        console.log(this.response);
        listSelector.innerHTML = "";
        listSelector.innerHTML += "&amp;lt;p style='margin: 0 auto;'&amp;gt;Sorry, there was an error&amp;lt;/p&amp;gt;"
      }
    };

    request.onerror = function(status, error) {
      console.log(error);
    };

    request.send();
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 31 May 2022 09:33:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Blog-search/m-p/641716#M28925</guid>
      <dc:creator>piersg</dc:creator>
      <dc:date>2022-05-31T09:33:50Z</dc:date>
    </item>
  </channel>
</rss>

