From f8052a6ecfca298e2acbbf4c84d3f7d2c6ae61c8 Mon Sep 17 00:00:00 2001 From: shockrah Date: Mon, 31 Jan 2022 15:09:55 -0800 Subject: [PATCH] * 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 --- .gitignore | 19 ++++++++----------- ts/category.ts | 25 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 1befca5..f78e2a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,25 @@ -/target -clippable-cli/store.json msg +*.swp +tmp/ +keys/ + api/target/ api/dev/ -*.swp -clippable-server/store.json 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/thumbs/ +api/*.db + build/ gitpage/public/ gitpage/resources/ gitpage/hugo.exe + aws/infra/keys/ aws/infra/*.hcl aws/infra/*.tfstate 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/terraform.tfvars aws/playbooks/hosts -tmp/ -keys/ diff --git a/ts/category.ts b/ts/category.ts index c8c9c09..93f7a76 100644 --- a/ts/category.ts +++ b/ts/category.ts @@ -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 = '#' }