nimbus-site/js/main.js
jinhojang6 2e163e3318 fix fetching from ghost api, remove unused code
Changes:
- Updates links to use new https://news.nimbus.team/ Ghost instance, rename links to use "News"
- Fixes URLs for the documentation sidebar in source/_data/sidebar.yml
- Drops fetching Fathoms tracker.js and embeds it by committing it at source/js/fathom.js
- Drops a bunch of unused dependencies like babel, browserify, js-yaml, or qrcode
- Drops themes/navy/source/js/main.js and replaces it with simpler source/js/main.js
- Drops scripts pulled in from CDNs like Moment.js, jQuery, Clipboard.js, and Highlight
- Drops everything in themes/navy/source/js including useless themes/navy/source/js/styles
- Drops over complicated JS bundling tasks from gulpfile.js
- Drops templates for unused popups:
  - themes/navy/layout/partial/community-popup.swig
  - themes/navy/layout/partial/projects-popup.swig

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2019-11-19 11:34:13 +01:00

53 lines
1.5 KiB
JavaScript

import fathom from './fathom.js'
const ghostApiUrl = 'https://our.status.im/ghost/api/v2'
const ghostApiKey = '10e7f8c1f793d2945ea1177076'
function customExcerpt(str) {
return str.split(/\s+/).slice(0,25).join(" ")
}
const newsPostTemplate = (post, excerpt) => (`
<div class="contribute blog">
<a href="https://our.status.im/${post.slug}" class="feature-image">
<img src="${post.feature_image}" alt="${post.title}"></a>
<h3>
<a href="https://our.status.im/${post.slug}">${post.title}</a>
</h3>
<p>${excerpt}</p>
<a href="https://our.status.im/${post.slug}">Read More <img src="/img/arrow_ogn.png"/></a>
</div>
`)
const fetchGhostBlogPosts = async () => {
let url = new URL(`${ghostApiUrl}/content/posts/`)
let params = {
key: ghostApiKey,
filter: 'tag:nimbus',
formats: 'plaintext',
order: 'published_at desc',
limit: 3,
}
url.search = new URLSearchParams(params).toString()
let resp = await fetch(url)
let json = await resp.json()
for (const post of json.posts.reverse()) {
let excerpt = post.custom_excerpt || customExcerpt(post.plaintext)
const div = document.querySelector('.contribute-wrap-blog')
div.insertAdjacentHTML('afterbegin', newsPostTemplate(post, excerpt))
}
}
const incrementFathomAnalytics = () => {
fathom('set', 'trackerUrl', '//fathom.status.im/collect');
fathom('set', 'siteId', 'KKAJT');
fathom('trackPageview');
}
document.addEventListener('DOMContentLoaded', (event) => {
fetchGhostBlogPosts()
incrementFathomAnalytics()
})