* Fixing url generation on thumbnails

This is mostly to remove the extensions which mess with OpenGraph meta fetching
Most services like Discord/Twitter/Facebook/Linkedin will not bother using the
Available opengraph metadata if an extension is detected as its assumed to be
a plain file
This commit is contained in:
shockrah
2022-01-31 15:09:55 -08:00
parent ac494608ff
commit f8052a6ecf
2 changed files with 25 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ class VideoMeta {
name: string|null
thumbnail: string|null
category: string
basename: string|null
constructor(raw: any) {
this.name = raw['name']
@@ -9,18 +10,26 @@ class VideoMeta {
let path = window.location.pathname
this.category = path.substring(path.lastIndexOf('/')+1)
this.basename = this.name ?
this.name.slice(0, this.name.lastIndexOf('.')) :
null
}
private clean_link(link: string) : string {
// NOTE: no need to url encode since browser does that anyway
for(const part of ['.', '-', '_', 'mp4', 'mkv', 'webm']) {
link = link.replace(part, ' ')
}
return link
}
title_link() : HTMLHeadingElement {
let container = document.createElement('h2')
let link = document.createElement('a')
if(this.name) {
const file_name = this.name.slice(0, this.name.lastIndexOf('.'))
link.href = `/clip/${this.category}/${file_name}`
link.text = this.name
for(const chars of ['.', '-', '_', 'mp4', 'mkv', 'webm']) {
link.text = link.text.replace(chars, ' ')
}
link.href = `/clip/${this.category}/${this.basename}`
link.text = this.clean_link(this.name)
} else {
link.href = '#'
link.text = this.name + 'ft. No thumbnail'
@@ -44,7 +53,7 @@ class VideoMeta {
}
let link = document.createElement('a')
if(this.name) {
link.href = `/clip/${this.category}/${this.name}`
link.href = `/clip/${this.category}/${this.basename}`
} else {
link.href = '#'
}