Remove markdown from body in push notifications (#374)
Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
parent
e3c60d1ef8
commit
4094adfa4f
|
@ -1,6 +1,7 @@
|
||||||
import webPush from 'web-push'
|
import webPush from 'web-push'
|
||||||
import models from '../models'
|
import models from '../models'
|
||||||
import { COMMENT_DEPTH_LIMIT } from '../../lib/constants'
|
import { COMMENT_DEPTH_LIMIT } from '../../lib/constants'
|
||||||
|
import removeMd from 'remove-markdown'
|
||||||
|
|
||||||
const webPushEnabled = process.env.NODE_ENV === 'production' ||
|
const webPushEnabled = process.env.NODE_ENV === 'production' ||
|
||||||
(process.env.VAPID_MAILTO && process.env.NEXT_PUBLIC_VAPID_PUBKEY && process.env.VAPID_PRIVKEY)
|
(process.env.VAPID_MAILTO && process.env.NEXT_PUBLIC_VAPID_PUBKEY && process.env.VAPID_PRIVKEY)
|
||||||
|
@ -17,10 +18,12 @@ if (webPushEnabled) {
|
||||||
|
|
||||||
const createPayload = (notification) => {
|
const createPayload = (notification) => {
|
||||||
// https://web.dev/push-notifications-display-a-notification/#visual-options
|
// https://web.dev/push-notifications-display-a-notification/#visual-options
|
||||||
const { title, ...options } = notification
|
let { title, body, ...options } = notification
|
||||||
|
if (body) body = removeMd(body)
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
title,
|
title,
|
||||||
options: {
|
options: {
|
||||||
|
body,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
icon: '/icons/icon_x96.png',
|
icon: '/icons/icon_x96.png',
|
||||||
...options
|
...options
|
||||||
|
|
Loading…
Reference in New Issue