Skip to content

Commit

Permalink
Compress 3 spaces down to 2 (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcarl authored Jan 29, 2025
1 parent 2569d6c commit 4bc94c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/helpers/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ export const compressLineBreaks = (s: string) => {
}
return s;
};

const TOO_MANY_SPACES = / {3}/g;
const APPROPRIATE_SPACES = " ";
export const compressSpaces = (s: string) => {
while (TOO_MANY_SPACES.test(s)) {
s = s.replaceAll(TOO_MANY_SPACES, APPROPRIATE_SPACES);
}
return s;
};
10 changes: 8 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
StoredMessage,
getJobPosts,
} from "./features/jobs-moderation/job-mod-helpers.js";
import { compressLineBreaks, simplifyString } from "./helpers/string.js";
import {
compressSpaces,
compressLineBreaks,
simplifyString,
} from "./helpers/string.js";
import { constructDiscordLink } from "./helpers/discord.js";
import { reactibotApiKey } from "./helpers/env.js";

Expand Down Expand Up @@ -275,7 +279,9 @@ const renderPost = (post: StoredMessage): RenderedPost => {
tags: post.tags,
type: post.type,
createdAt: post.createdAt,
description: renderMdToHtml(compressLineBreaks(post.description)),
description: renderMdToHtml(
compressLineBreaks(compressSpaces(post.description)),
),
messageLink: constructDiscordLink(post.message),
reactions: post.message.reactions.cache.map((r) => [
r.emoji.name ?? "☐",
Expand Down

0 comments on commit 4bc94c1

Please sign in to comment.