use better image sizes

This commit is contained in:
2023-03-13 21:42:44 +10:00
parent 0385672364
commit dd5ac3a2b4
3 changed files with 23 additions and 5 deletions

View File

@@ -21,14 +21,30 @@ const props = defineProps({
const computedContent = computed(() => {
let html = "";
const regex = new RegExp(
// Convert local links to router-links
const regexHref = new RegExp(
`<a ([^>]*?)href="${
(import.meta as ImportMetaExtras).env.APP_URL
}(.*?>.*?)</a>`,
"ig"
);
html = props.html.replace(regexHref, '<router-link $1to="$2</router-link>');
html = props.html.replace(regex, '<router-link $1to="$2</router-link>');
// Update local images to use at most the large size
const regexImg = new RegExp(
`<img ([^>]*?)src="${
(import.meta as ImportMetaExtras).env.APP_URL
}/uploads/([^"]*?)"`,
"ig"
);
html = html.replace(
regexImg,
`<img $1src="${
(import.meta as ImportMetaExtras).env.APP_URL
}/uploads/$2?size=large"`
);
// Sanitize HTML
html = DOMPurify.sanitize(html);
return {

View File

@@ -91,6 +91,7 @@ import { computed, inject, ref, useSlots, watch } from "vue";
import { openDialog } from "vue3-promise-dialog";
import { api } from "../helpers/api";
import { MediaResponse } from "../helpers/api.types";
import { imageMedium } from "../helpers/image";
import { toTitleCase } from "../helpers/string";
import { isEmpty } from "../helpers/utils";
import { isUUID } from "../helpers/uuid";
@@ -240,7 +241,7 @@ watch(
const data = result.data as MediaResponse;
if (data && data.medium) {
mediaUrl.value = data.medium.url;
mediaUrl.value = imageMedium(data.medium.url);
}
} catch (error) {
/* empty */

View File

@@ -60,7 +60,7 @@ import { computed, onMounted, reactive, ref, watch } from "vue";
import { api } from "../helpers/api";
import { MediaResponse } from "../helpers/api.types";
import { SMDate } from "../helpers/datetime";
import { imageLoad } from "../helpers/image";
import { imageLoad, imageMedium } from "../helpers/image";
import {
excerpt,
replaceHtmlEntites,
@@ -251,7 +251,8 @@ onMounted(async () => {
watch(
() => imageUrl.value,
(value) => {
styleObject["backgroundImage"] = `url('${value}')`;
const url = imageMedium(value);
styleObject["backgroundImage"] = `url('${url}')`;
}
);
</script>