BetterGifAltText sanity checks
This commit is contained in:
parent
48477e1959
commit
0677df7818
1 changed files with 9 additions and 4 deletions
|
@ -27,14 +27,19 @@ export default definePlugin({
|
||||||
altify(props: any) {
|
altify(props: any) {
|
||||||
if (props.alt !== "GIF") return;
|
if (props.alt !== "GIF") return;
|
||||||
|
|
||||||
const url = props.original || props.src;
|
const url: string = props.original || props.src;
|
||||||
const name = url
|
let name = url
|
||||||
.slice(url.lastIndexOf("/") + 1)
|
.slice(url.lastIndexOf("/") + 1)
|
||||||
.replace(/\d/g, "") // strip numbers
|
.replace(/\d/g, "") // strip numbers
|
||||||
.replace(/.gif$/, "") // strip extension
|
.replace(/.gif$/, "") // strip extension
|
||||||
.replace(/[,-_ ]+/g, " "); // Replace common delimiters with space
|
.split(/[,\-_ ]+/g)
|
||||||
|
.slice(0, 20)
|
||||||
|
.join(" ");
|
||||||
|
if (name.length > 300) {
|
||||||
|
name = name.slice(0, 300) + "...";
|
||||||
|
}
|
||||||
|
|
||||||
if (name.length) props.alt += ` - ${name}`;
|
if (name) props.alt += ` - ${name}`;
|
||||||
|
|
||||||
return props.alt;
|
return props.alt;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue