Skip to content

Commit

Permalink
feat: show alt text instead of images in teasers (#9107)
Browse files Browse the repository at this point in the history
* feat: show alt text instead of images in teasers

* refactor: from utils to local function
  • Loading branch information
gasoved committed Dec 14, 2020
1 parent 3ba0575 commit d28581e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/topics/teaser.js
Expand Up @@ -76,7 +76,7 @@ module.exports = function (Topics) {
if (tidToPost[topic.tid]) {
tidToPost[topic.tid].index = meta.config.teaserPost === 'first' ? 1 : counts[index];
if (tidToPost[topic.tid].content) {
tidToPost[topic.tid].content = utils.stripHTMLTags(tidToPost[topic.tid].content, tags);
tidToPost[topic.tid].content = utils.stripHTMLTags(replaceImgWithAltText(tidToPost[topic.tid].content), tags);
}
}
return tidToPost[topic.tid];
Expand All @@ -86,6 +86,10 @@ module.exports = function (Topics) {
return result.teasers;
};

function replaceImgWithAltText(str) {
return String(str).replace(/<img .*?alt="(.*?)"[^>]*>/gi, '$1');
}

async function handleBlocks(uid, teasers) {
const blockedUids = await user.blocks.list(uid);
if (!blockedUids.length) {
Expand Down

0 comments on commit d28581e

Please sign in to comment.