2020-07-25 10:21:52 -07:00
|
|
|
export const buildDict = (fn, ...args) => {
|
|
|
|
const dict = {};
|
|
|
|
for (let [key, value] of fn(...args)) {
|
|
|
|
dict[key] = value;
|
|
|
|
}
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const buildList = (fn, ...args) => {
|
|
|
|
const list = [];
|
|
|
|
for (let value of fn(...args)) {
|
|
|
|
list.push(value);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2020-09-23 12:29:55 -07:00
|
|
|
|
|
|
|
export const head = ({title, description, banner}) => {
|
|
|
|
const meta = { meta: [] };
|
|
|
|
|
|
|
|
if (title) {
|
|
|
|
title += ' • Zaimki.pl';
|
|
|
|
meta.title = title;
|
|
|
|
meta.meta.push({ hid: 'og:title', property: 'og:title', content: title });
|
|
|
|
meta.meta.push({ hid: 'twitter:title', property: 'twitter:title', content: title });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (description) {
|
|
|
|
meta.meta.push({ hid: 'description', name: 'description', content: description });
|
|
|
|
meta.meta.push({ hid: 'og:description', property: 'og:description', content: description });
|
|
|
|
meta.meta.push({ hid: 'twitter:description', property: 'twitter:description', content: description });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (banner) {
|
2020-10-13 12:49:08 -07:00
|
|
|
banner = process.env.BASE_URL + '/' + banner;
|
2020-09-23 12:29:55 -07:00
|
|
|
meta.meta.push({ hid: 'og:logo', property: 'og:logo', content: banner });
|
|
|
|
meta.meta.push({ hid: 'twitter:image', property: 'twitter:image', content: banner });
|
|
|
|
}
|
|
|
|
|
|
|
|
return meta;
|
|
|
|
}
|
2020-09-29 08:59:23 -07:00
|
|
|
|
|
|
|
export const clearUrl = url => {
|
|
|
|
url = url.trim()
|
|
|
|
.replace('http://www.', '')
|
|
|
|
.replace('https://www.', '')
|
|
|
|
.replace('http://', '')
|
|
|
|
.replace('https://', '');
|
|
|
|
|
|
|
|
const qPos = url.indexOf('?')
|
|
|
|
if (qPos > -1) {
|
|
|
|
url = url.substr(0, qPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
const hPos = url.indexOf('#')
|
|
|
|
if (hPos > -1) {
|
|
|
|
url = url.substr(0, hPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url.substr(url.length - 1) === '/') {
|
|
|
|
url = url.substr(0, url.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return decodeURIComponent(url);
|
|
|
|
}
|
2020-10-13 12:49:08 -07:00
|
|
|
|
|
|
|
export const makeId = (length, characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') => {
|
|
|
|
let result = '';
|
|
|
|
const charactersLength = characters.length;
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|