chore: additional formatting w/prettier

This commit is contained in:
Cory Dransfeldt 2023-03-25 14:09:26 -07:00
parent ea75e585e1
commit ee77555c32
No known key found for this signature in database
39 changed files with 1544 additions and 1584 deletions

View file

@ -1,44 +1,44 @@
const { DateTime } = require('luxon')
module.exports = {
dateForFeed: (date) => {
return new Date(date).toISOString()
},
toDateTime: (date) => {
const formatted = DateTime.fromISO(date)
dateForFeed: (date) => {
return new Date(date).toISOString()
},
toDateTime: (date) => {
const formatted = DateTime.fromISO(date)
const trail = (number) => {
return parseInt(number, 10) < 10 ? `0${number}` : number
}
const trail = (number) => {
return parseInt(number, 10) < 10 ? `0${number}` : number
}
return `${formatted.year}-${trail(formatted.month)}-${trail(formatted.day)} ${trail(
formatted.hour
)}:${trail(formatted.minute)}`
},
toDateTimeFromUnix: (date) => {
const formatted = DateTime.fromSeconds(parseInt(date, 10))
return `${formatted.year}-${trail(formatted.month)}-${trail(formatted.day)} ${trail(
formatted.hour
)}:${trail(formatted.minute)}`
},
toDateTimeFromUnix: (date) => {
const formatted = DateTime.fromSeconds(parseInt(date, 10))
const trail = (number) => {
return parseInt(number, 10) < 10 ? `0${number}` : number
}
const trail = (number) => {
return parseInt(number, 10) < 10 ? `0${number}` : number
}
return `${trail(formatted.month)}.${trail(formatted.day)}.${formatted.year} ${trail(
formatted.hour
)}:${trail(formatted.minute)}`
},
isoDateOnly: (date) => {
let d = new Date(date)
let month = '' + (d.getMonth() + 1)
let day = '' + d.getDate()
let year = d.getFullYear()
return `${trail(formatted.month)}.${trail(formatted.day)}.${formatted.year} ${trail(
formatted.hour
)}:${trail(formatted.minute)}`
},
isoDateOnly: (date) => {
let d = new Date(date)
let month = '' + (d.getMonth() + 1)
let day = '' + d.getDate()
let year = d.getFullYear()
if (month.length < 2) month = '0' + month
if (day.length < 2) day = '0' + day
if (month.length < 2) month = '0' + month
if (day.length < 2) day = '0' + day
return [month, day, year].join('.')
},
rssLastUpdatedDate: (collection) => {
if (!collection || !collection.length) return ''
return collection[0].publishedAt
},
return [month, day, year].join('.')
},
rssLastUpdatedDate: (collection) => {
if (!collection || !collection.length) return ''
return collection[0].publishedAt
},
}

View file

@ -2,66 +2,66 @@ const marked = require('marked')
const sanitizeHTML = require('sanitize-html')
module.exports = {
trim: (string, limit) => {
return string.length <= limit ? string : `${string.slice(0, limit)}...`
},
postPath: (path) => {
if (path.includes('micro/')) return path
return `/micro/${path}`
},
stripIndex: (path) => {
return path.replace('/index.html', '/')
},
mdToHtml: (content) => {
return marked.parse(content)
},
getFirstAttachment: (post) => {
if (post && post.attachments && post.attachments.length > 0) {
return post.attachments[0].url ? post.attachments[0].url : post.attachments[0]
trim: (string, limit) => {
return string.length <= limit ? string : `${string.slice(0, limit)}...`
},
postPath: (path) => {
if (path.includes('micro/')) return path
return `/micro/${path}`
},
stripIndex: (path) => {
return path.replace('/index.html', '/')
},
mdToHtml: (content) => {
return marked.parse(content)
},
getFirstAttachment: (post) => {
if (post && post.attachments && post.attachments.length > 0) {
return post.attachments[0].url ? post.attachments[0].url : post.attachments[0]
}
return '/assets/img/social-card.png'
},
webmentionsByUrl: (webmentions, url) => {
const allowedTypes = ['mention-of', 'in-reply-to', 'like-of', 'repost-of']
const data = {
'like-of': [],
'repost-of': [],
'in-reply-to': [],
}
const hasRequiredFields = (entry) => {
const { author, published, content } = entry
return author.name && published && content
}
const filtered =
webmentions
?.filter((entry) => entry['wm-target'] === `https://coryd.dev${url}`)
.filter((entry) => allowedTypes.includes(entry['wm-property'])) || []
filtered.forEach((m) => {
if (data[m['wm-property']]) {
const isReply = m['wm-property'] === 'in-reply-to'
const isValidReply = isReply && hasRequiredFields(m)
if (isReply) {
if (isValidReply) {
m.sanitized = sanitizeHTML(m.content.html)
data[m['wm-property']].unshift(m)
}
return
}
return '/assets/img/social-card.png'
},
webmentionsByUrl: (webmentions, url) => {
const allowedTypes = ['mention-of', 'in-reply-to', 'like-of', 'repost-of']
data[m['wm-property']].unshift(m)
}
})
const data = {
'like-of': [],
'repost-of': [],
'in-reply-to': [],
}
data['in-reply-to'].sort((a, b) =>
a.published > b.published ? 1 : b.published > a.published ? -1 : 0
)
const hasRequiredFields = (entry) => {
const { author, published, content } = entry
return author.name && published && content
}
const filtered =
webmentions
?.filter((entry) => entry['wm-target'] === `https://coryd.dev${url}`)
.filter((entry) => allowedTypes.includes(entry['wm-property'])) || []
filtered.forEach((m) => {
if (data[m['wm-property']]) {
const isReply = m['wm-property'] === 'in-reply-to'
const isValidReply = isReply && hasRequiredFields(m)
if (isReply) {
if (isValidReply) {
m.sanitized = sanitizeHTML(m.content.html)
data[m['wm-property']].unshift(m)
}
return
}
data[m['wm-property']].unshift(m)
}
})
data['in-reply-to'].sort((a, b) =>
a.published > b.published ? 1 : b.published > a.published ? -1 : 0
)
return data
},
return data
},
}

View file

@ -1,12 +1,12 @@
const ALBUM_DENYLIST = ['no-love-deep-web']
module.exports = {
artist: (media) =>
`https://cdn.coryd.dev/artists/${media.replace(/\s+/g, '-').toLowerCase()}.jpg`,
album: (media) => {
const img = !ALBUM_DENYLIST.includes(media.name.replace(/\s+/g, '-').toLowerCase())
? media.image[media.image.length - 1]['#text']
: `https://cdn.coryd.dev/artists/${media.name.replace(/\s+/g, '-').toLowerCase()}.jpg`
return img
},
artist: (media) =>
`https://cdn.coryd.dev/artists/${media.replace(/\s+/g, '-').toLowerCase()}.jpg`,
album: (media) => {
const img = !ALBUM_DENYLIST.includes(media.name.replace(/\s+/g, '-').toLowerCase())
? media.image[media.image.length - 1]['#text']
: `https://cdn.coryd.dev/artists/${media.name.replace(/\s+/g, '-').toLowerCase()}.jpg`
return img
},
}

View file

@ -1,6 +1,6 @@
const { DateTime } = require('luxon')
module.exports = (collection) => {
if (!collection || !collection.length) return ''
return collection[0].publishedAt
if (!collection || !collection.length) return ''
return collection[0].publishedAt
}