diff --git a/web/app/common/api.js b/web/app/common/api.js index 59dc06de..46cdb174 100644 --- a/web/app/common/api.js +++ b/web/app/common/api.js @@ -12,7 +12,10 @@ export const find = ({ url }) => fetcher.get(`/find?url=${url}&sort=-score&forma export const last = ({ siteId, max }) => fetcher.get(`/last/${max}?site=${siteId}`); -export const count = ({ url, siteId }) => fetcher.get(`/count?url=${url}&site=${siteId}`); +export const count = ({ urls, siteId }) => fetcher.post({ + url: `/count?site=${siteId}`, + body: urls, +}); export const getComment = ({ id }) => fetcher.get(`/id/${id}?url=${url}`); diff --git a/web/app/components/list-comments/list-comments.scss b/web/app/components/list-comments/list-comments.scss index e4f0b120..ce27387e 100644 --- a/web/app/components/list-comments/list-comments.scss +++ b/web/app/components/list-comments/list-comments.scss @@ -1,4 +1,3 @@ .list-comments { - position: relative; font-family: 'PT Sans', Helvetica, Arial, sans-serif; } diff --git a/web/app/counter.js b/web/app/counter.js index 5a505008..c3006883 100644 --- a/web/app/counter.js +++ b/web/app/counter.js @@ -9,7 +9,7 @@ if (document.readyState !== 'interactive') { } function init() { - const nodes = document.getElementsByClassName(COUNTER_NODE_CLASSNAME); + const nodes = [].slice.call(document.getElementsByClassName(COUNTER_NODE_CLASSNAME)); if (!nodes) { console.error('Remark42: Can\'t find counter nodes.'); @@ -28,10 +28,14 @@ function init() { return; } - [].slice.call(nodes).forEach(node => { - const url = node.dataset.url || remark_config.url || window.location.href; - api.count({ url, siteId: remark_config.site_id }) - .then(({ count }) => { node.innerHTML = count; }); - }); + const map = nodes.reduce((acc, node) => { + acc[node.dataset.url || remark_config.url || window.location.href] = node; + return acc; + }, {}); + + api.count({ urls: Object.keys(map), siteId: remark_config.site_id }) + .then(res => { + res.forEach(item => (map[item.url].innerHTML = item.count)); + }); } diff --git a/web/app/remark.js b/web/app/remark.js index 97009fae..0b28667a 100644 --- a/web/app/remark.js +++ b/web/app/remark.js @@ -3,6 +3,7 @@ import 'common/polyfills'; // TODO: check it import { h, render } from 'preact'; import Root from './components/root'; +import ListComments from './components/list-comments'; // TODO: temp solution for extracting styles import { NODE_ID } from './common/constants'; diff --git a/web/webpack.config.js b/web/webpack.config.js index 8ee7bd5b..48857e75 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -38,10 +38,10 @@ const commonStyleLoaders = [ module.exports = { context: __dirname, entry: { - remark: './app/remark', embed: './app/embed', counter: './app/counter', 'last-comments': './app/last-comments', + remark: './app/remark', }, output: { path: publicFolder,