Guest User

Untitled

a guest
Mar 1st, 2025
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.25 KB | None | 0 0
  1. <script type="application/javascript">
  2. let tags = ["mytag"]; // EDIT THIS
  3.  
  4. ///////////////////////////////////////////
  5.  
  6. window.addEventListener("load", async () => {
  7.     let response = await fetch("/graphql", {
  8.         method: "POST",
  9.         body: JSON.stringify({
  10.         query: `query ($tags: [String!]) { pages { list(limit:10, orderBy: CREATED, orderByDirection:DESC, tags: $tags) { id \npath \ntitle \ndescription \nisPublished } } }`,
  11.         variables: {
  12.             tags: tags,
  13.         }
  14.         }),
  15.         headers: {
  16.             "Content-Type": "application/json",
  17.         },
  18.     }, );
  19.  
  20.     let data = await response.json();
  21.     let pages = data["data"]["pages"]["list"];
  22.     let container = document.querySelector("#pages");
  23.     let pageElements = pages.filter(page => page.isPublished)
  24.         .map(({path: path, title: title, description: description, id: _}) => {
  25.             let pageEl = document.createElement("li");
  26.             pageEl.classList.add("page");
  27.             pageEl.innerHTML = `<p><a href="${path}">${title}</a></p><p>${description}</p>`;
  28.             return pageEl;
  29.         });
  30.     if (pageElements.length == 0) {
  31.         return
  32.     }
  33.     container.innerHTML = "";
  34.     container.append(...pageElements);
  35. });
  36. </script>
Advertisement
Add Comment
Please, Sign In to add comment