MCPcopy
hub / github.com/microfeed/microfeed / webItem

Function webItem

common-src/StringUtils.js:250–275  ·  view source on GitHub ↗

* Public urls

(itemId, itemTitle = null, baseUrl = '/', locale = 'en')

Source from the content-addressed store, hash-verified

248 * Public urls
249 */
250function webItem(itemId, itemTitle = null, baseUrl = '/', locale = 'en') {
251 if (itemTitle) {
252 const title = truncateString(itemTitle, 50, false);
253 let slug = slugify(title, {
254 lower: true,
255 strict: true, // strip special characters except replacement
256 locale,
257 });
258 // Fallback to a custom implementation to deal with all non-English characters.
259 if (!slug) {
260 slug = title
261 .toString()
262 .normalize('NFKD')
263 .toLowerCase()
264 .trim()
265 .replace(/['!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g, '-')
266 .replace(/\s+/g, '-')
267 .replace(/\_/g, '-')
268 .replace(/\-\-+/g, '-')
269 .replace(/\-$/g, '');
270 }
271 return urlJoin(baseUrl, `/i/${slug}-${itemId}/`);
272 } else {
273 return urlJoin(baseUrl, `/i/${itemId}/`);
274 }
275}
276
277export const PUBLIC_URLS = {
278 webFeed: (baseUrl = '/') => {

Callers 1

StringUtils.jsFile · 0.85

Calls 2

truncateStringFunction · 0.85
urlJoinFunction · 0.85

Tested by

no test coverage detected