mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-05 15:29:50 +00:00
fix errors with data structure
This commit is contained in:
parent
6da297d1d2
commit
ae2265df21
@ -165,6 +165,6 @@ export interface NewsItemType {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
startdate: { date: DateTime };
|
||||
enddate: { date: DateTime | null}
|
||||
startDate: DateTime;
|
||||
endDate: DateTime | null;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
</template>
|
||||
<template #body>
|
||||
<p class="news-date">
|
||||
{{ $t('widget.news.date') }}: <span>{{ formatDate(item.startdate.date) }}</span>
|
||||
<span>{{ $d(newsItemStartDate(), 'short') }}</span>
|
||||
</p>
|
||||
<div v-html="convertMarkdownToHtml(item.content)"></div>
|
||||
</template>
|
||||
@ -30,12 +30,17 @@ import DOMPurify from 'dompurify';
|
||||
import { DateTime, NewsItemType } from "../../../types";
|
||||
import type { PropType } from 'vue'
|
||||
import { defineProps, ref } from "vue";
|
||||
import {dateToISO} from "../../../chill/js/date";
|
||||
import {ISOToDatetime} from "../../../chill/js/date";
|
||||
|
||||
const props = defineProps({
|
||||
item: {
|
||||
type: Object as PropType<NewsItemType>,
|
||||
required: true
|
||||
},
|
||||
maxLength: {
|
||||
type: Number,
|
||||
required: false,
|
||||
default: 200,
|
||||
}
|
||||
})
|
||||
|
||||
@ -52,13 +57,13 @@ const closeModal = () => {
|
||||
showModal.value = false;
|
||||
};
|
||||
|
||||
const shouldTruncate = (content: string, maxLength = 100): boolean => {
|
||||
return content.length > maxLength;
|
||||
const shouldTruncate = (content: string): boolean => {
|
||||
return content.length > props.maxLength;
|
||||
};
|
||||
|
||||
const truncateContent = (content: string, maxLength = 100): string => {
|
||||
if (shouldTruncate(content, maxLength)) {
|
||||
let truncatedContent = content.slice(0, maxLength);
|
||||
const truncateContent = (content: string): string => {
|
||||
if (shouldTruncate(content)) {
|
||||
let truncatedContent = content.slice(0, props.maxLength);
|
||||
let linkDepth = 0;
|
||||
let linkStartIndex = -1;
|
||||
|
||||
@ -103,13 +108,13 @@ const convertMarkdownToHtml = (markdown: string): string => {
|
||||
return DOMPurify.sanitize(rawHtml)
|
||||
};
|
||||
|
||||
const prepareContent = (content: string, maxLength = 200): string => {
|
||||
const prepareContent = (content: string): string => {
|
||||
const htmlContent = convertMarkdownToHtml(content);
|
||||
return truncateContent(htmlContent, maxLength);
|
||||
return truncateContent(htmlContent);
|
||||
};
|
||||
|
||||
const formatDate = (datetime: DateTime): string|null => {
|
||||
return dateToISO(new Date(datetime.toString()))
|
||||
const newsItemStartDate = (): null|Date => {
|
||||
return ISOToDatetime(props.item?.startDate.datetime);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user