Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="application/javascript">
- let tags = ["mytag"]; // EDIT THIS
- ///////////////////////////////////////////
- window.addEventListener("load", async () => {
- let response = await fetch("/graphql", {
- method: "POST",
- body: JSON.stringify({
- query: `query ($tags: [String!]) { pages { list(limit:10, orderBy: CREATED, orderByDirection:DESC, tags: $tags) { id \npath \ntitle \ndescription \nisPublished } } }`,
- variables: {
- tags: tags,
- }
- }),
- headers: {
- "Content-Type": "application/json",
- },
- }, );
- let data = await response.json();
- let pages = data["data"]["pages"]["list"];
- let container = document.querySelector("#pages");
- let pageElements = pages.filter(page => page.isPublished)
- .map(({path: path, title: title, description: description, id: _}) => {
- let pageEl = document.createElement("li");
- pageEl.classList.add("page");
- pageEl.innerHTML = `<p><a href="${path}">${title}</a></p><p>${description}</p>`;
- return pageEl;
- });
- if (pageElements.length == 0) {
- return
- }
- container.innerHTML = "";
- container.append(...pageElements);
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment