You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2024/02/15 18:12:31 UTC

(airflow-site) branch main updated: Add a condition to avoide errors (#956)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow-site.git


The following commit(s) were added to refs/heads/main by this push:
     new 408a1e1dd8 Add a condition to avoide errors (#956)
408a1e1dd8 is described below

commit 408a1e1dd86b08976f1b9151acc97e4380129ea7
Author: Satoshi S <73...@users.noreply.github.com>
AuthorDate: Thu Feb 15 12:12:26 2024 -0600

    Add a condition to avoide errors (#956)
---
 landing-pages/src/js/searchBlogPosts.js | 116 ++++++++++++++++----------------
 1 file changed, 58 insertions(+), 58 deletions(-)

diff --git a/landing-pages/src/js/searchBlogPosts.js b/landing-pages/src/js/searchBlogPosts.js
index 5cd516e1bd..c63f1c7c4f 100644
--- a/landing-pages/src/js/searchBlogPosts.js
+++ b/landing-pages/src/js/searchBlogPosts.js
@@ -23,68 +23,68 @@ const query = new URLSearchParams(window.location.search);
 const searchString = query.get("q");
 document.querySelector("#search").value = searchString;
 
-const $target = document.querySelector(".list-items");
+if (window.location.pathname.startsWith("/blog") && searchString) {
+  const $target = document.querySelector(".list-items");
+  const $itemTemplate = $target.firstElementChild.cloneNode(true);
 
-const $itemTemplate = $target.firstElementChild.cloneNode(true);
+  const formatDate = (date) => {
+    const dateOptions = {weekday: "short", year: "numeric", month: "short", day: "numeric"};
+    return new Date(date).toLocaleDateString("en-US", dateOptions);
+  };
 
+  const setTags = (tagsContainer, tags) => {
+    while (tagsContainer.firstChild) {
+      tagsContainer.removeChild(tagsContainer.firstChild);
+    }
+    tags.forEach((tag) => {
+      const tagElement = document.createElement("a");
+      tagsContainer.appendChild(tagElement);
+      tagElement.setAttribute("class", "tag");
+      tagElement.setAttribute("href", `/blog/tags/${tag}/`);
+      tagElement.innerText = tag;
+    });
+  };
 
-const formatDate = (date) => {
-  const dateOptions = {weekday: "short", year: "numeric", month: "short", day: "numeric"};
-  return new Date(date).toLocaleDateString("en-US", dateOptions);
-};
+  Promise.all([
+    fetch("/_gen/indexes/en/blog-index.json"),
+    fetch("/_gen/indexes/en/blog-posts.json")
+  ]).then(function([indexResp, postsResp]) {
+    return Promise.all([
+      indexResp.json(),
+      postsResp.json()
+    ]);
+  }).then(function([index, posts]) {
+    const lunrIndex = lunr.Index.load(index);
+    const matches = lunrIndex.search(searchString);
+    const results = [];
+    matches.forEach(function(match) {
+      posts.filter((post) => post.title === match.ref)
+        .forEach((post) => {
+          results.push({post, match});
+        });
+    });
+    results.sort((a, b) => a.match.score - b.match.score);
 
-const setTags = (tagsContainer, tags) => {
-  while (tagsContainer.firstChild) {
-    tagsContainer.removeChild(tagsContainer.firstChild);
-  }
-  tags.forEach((tag) => {
-    const tagElement = document.createElement("a");
-    tagsContainer.appendChild(tagElement);
-    tagElement.setAttribute("class", "tag");
-    tagElement.setAttribute("href", `/blog/tags/${tag}/`);
-    tagElement.innerText = tag;
-  });
-};
+    if (results.length > 10) {
+      results.splice(10, results.length - 10);
+    }
 
-Promise.all([
-  fetch("/_gen/indexes/en/blog-index.json"),
-  fetch("/_gen/indexes/en/blog-posts.json")
-]).then(function([indexResp, postsResp]) {
-  return Promise.all([
-    indexResp.json(),
-    postsResp.json()
-  ]);
-}).then(function([index, posts]) {
-  const lunrIndex = lunr.Index.load(index);
-  const matches = lunrIndex.search(searchString);
-  const results = [];
-  matches.forEach(function(match) {
-    posts.filter((post) => post.title === match.ref)
-      .forEach((post) => {
-        results.push({post, match});
+    if (results.length > 0) {
+      while ($target.firstChild) {
+        $target.removeChild($target.firstChild);
+      }
+      results.forEach((result) => {
+        const $newResultItem = $itemTemplate.cloneNode(true);
+        $newResultItem.querySelector(".box-event__blogpost--header").innerText = result.post.title;
+        $newResultItem.querySelector(".box-event__blogpost--author").innerText = result.post.author;
+        $newResultItem.querySelector(".box-event__blogpost--description").innerText = result.post.description;
+        $newResultItem.querySelector(".box-event__blogpost--date").innerText = formatDate(result.post.date);
+        setTags($newResultItem.querySelector(".box-event__blogpost--metadata > .tags-container"), result.post.tags);
+        $newResultItem.querySelector(".box-event__blogpost > a").href = `/blog/${result.post.url}/`;
+        $target.append($newResultItem);
       });
-  });
-  results.sort((a, b) => a.match.score - b.match.score);
-
-  if (results.length > 10) {
-    results.splice(10, results.length - 10);
-  }
-
-  if (results.length > 0) {
-    while ($target.firstChild) {
-      $target.removeChild($target.firstChild);
+    } else {
+      $target.innerHTML = "<div>No search results found</div>";
     }
-    results.forEach((result) => {
-      const $newResultItem = $itemTemplate.cloneNode(true);
-      $newResultItem.querySelector(".box-event__blogpost--header").innerText = result.post.title;
-      $newResultItem.querySelector(".box-event__blogpost--author").innerText = result.post.author;
-      $newResultItem.querySelector(".box-event__blogpost--description").innerText = result.post.description;
-      $newResultItem.querySelector(".box-event__blogpost--date").innerText = formatDate(result.post.date);
-      setTags($newResultItem.querySelector(".box-event__blogpost--metadata > .tags-container"), result.post.tags);
-      $newResultItem.querySelector(".box-event__blogpost > a").href = `/blog/${result.post.url}/`;
-      $target.append($newResultItem);
-    });
-  } else {
-    $target.innerHTML = "<div>No search results found</div>";
-  }
-});
+  });
+}