Created
August 30, 2023 02:00
-
-
Save goofmint/149ee53576185d2d60b789c27174d42a to your computer and use it in GitHub Desktop.
Render updated pages in wiki.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.0-beta.2/timeago.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.0-beta.2/timeago.locales.min.js"></script> | |
<script> | |
const token = 'YOUR_WIKIJS_TOKEN'; | |
const locale = 'ja'; | |
const pageTag = 'service'; | |
const limit = 10; | |
const DOMContentLoaded = () => { | |
renderNewPage(); | |
}; | |
const renderNewPage = async () => { | |
const body = { | |
operationName: null, | |
variables: { locale, pageTag, limit}, | |
query: `query ($locale: String, $pageTag: [String!], $limit: Int) { | |
pages { | |
list(orderBy: UPDATED, orderByDirection: DESC, locale: $locale, tags: $pageTag, limit: $limit) { | |
path | |
title | |
createdAt | |
} | |
} | |
}` | |
}; | |
const res = await fetch("/graphql", { | |
method: "POST", | |
headers: { | |
authorization: `Bearer ${token}`, | |
"content-type": "application/json", | |
}, | |
body: JSON.stringify(body), | |
}); | |
const { data } = await res.json(); | |
const dom = document.querySelector("#new"); | |
dom.innerHTML = data.pages.list.map(page => ` | |
<li> | |
<a href="${page.path}">${page.title}</a> 🕒 ${timeago.format(page.createdAt, locale)} | |
</li> | |
`).join(''); | |
}; | |
document.addEventListener('DOMContentLoaded', DOMContentLoaded); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment