* 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

19
.gitignore vendored
View File

@ -1,28 +1,25 @@
/target
clippable-cli/store.json
msg msg
*.swp
tmp/
keys/
api/target/ api/target/
api/dev/ api/dev/
*.swp
clippable-server/store.json
api/vids/ api/vids/
frontend/themes/clippable/static/js/index.js
frontend/public/
frontend/themes/clippable/static/js/category.js
frontend/themes/clippable/static/js/collection.js
api/static/js/ api/static/js/
api/thumbs/ api/thumbs/
api/*.db
build/ build/
gitpage/public/ gitpage/public/
gitpage/resources/ gitpage/resources/
gitpage/hugo.exe gitpage/hugo.exe
aws/infra/keys/ aws/infra/keys/
aws/infra/*.hcl aws/infra/*.hcl
aws/infra/*.tfstate aws/infra/*.tfstate
aws/infra/*.backup aws/infra/*.backup
aws/infra/.terraform/providers/registry.terraform.io/hashicorp/aws/3.63.0/linux_amd64/terraform-provider-aws_v3.63.0_x5 aws/infra/.terraform/
aws/infra/plan aws/infra/plan
aws/infra/terraform.tfvars aws/infra/terraform.tfvars
aws/playbooks/hosts aws/playbooks/hosts
tmp/
keys/

View File

@ -2,6 +2,7 @@ class VideoMeta {
name: string|null name: string|null
thumbnail: string|null thumbnail: string|null
category: string category: string
basename: string|null
constructor(raw: any) { constructor(raw: any) {
this.name = raw['name'] this.name = raw['name']
@ -9,18 +10,26 @@ class VideoMeta {
let path = window.location.pathname let path = window.location.pathname
this.category = path.substring(path.lastIndexOf('/')+1) 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 { title_link() : HTMLHeadingElement {
let container = document.createElement('h2') let container = document.createElement('h2')
let link = document.createElement('a') let link = document.createElement('a')
if(this.name) { if(this.name) {
const file_name = this.name.slice(0, this.name.lastIndexOf('.')) link.href = `/clip/${this.category}/${this.basename}`
link.href = `/clip/${this.category}/${file_name}` link.text = this.clean_link(this.name)
link.text = this.name
for(const chars of ['.', '-', '_', 'mp4', 'mkv', 'webm']) {
link.text = link.text.replace(chars, ' ')
}
} else { } else {
link.href = '#' link.href = '#'
link.text = this.name + 'ft. No thumbnail' link.text = this.name + 'ft. No thumbnail'
@ -44,7 +53,7 @@ class VideoMeta {
} }
let link = document.createElement('a') let link = document.createElement('a')
if(this.name) { if(this.name) {
link.href = `/clip/${this.category}/${this.name}` link.href = `/clip/${this.category}/${this.basename}`
} else { } else {
link.href = '#' link.href = '#'
} }