💂♂️ fixed lint and prittier
This commit is contained in:
68
lib/utils.ts
68
lib/utils.ts
@@ -1,47 +1,65 @@
|
||||
export function formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
const date = new Date(dateString)
|
||||
const months = [
|
||||
'ianuarie', 'februarie', 'martie', 'aprilie', 'mai', 'iunie',
|
||||
'iulie', 'august', 'septembrie', 'octombrie', 'noiembrie', 'decembrie'
|
||||
];
|
||||
'ianuarie',
|
||||
'februarie',
|
||||
'martie',
|
||||
'aprilie',
|
||||
'mai',
|
||||
'iunie',
|
||||
'iulie',
|
||||
'august',
|
||||
'septembrie',
|
||||
'octombrie',
|
||||
'noiembrie',
|
||||
'decembrie',
|
||||
]
|
||||
|
||||
return `${date.getDate()} ${months[date.getMonth()]} ${date.getFullYear()}`;
|
||||
return `${date.getDate()} ${months[date.getMonth()]} ${date.getFullYear()}`
|
||||
}
|
||||
|
||||
export function formatRelativeDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
const now = new Date();
|
||||
const diffTime = Math.abs(now.getTime() - date.getTime());
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
const date = new Date(dateString)
|
||||
const now = new Date()
|
||||
const diffTime = Math.abs(now.getTime() - date.getTime())
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
|
||||
|
||||
if (diffDays === 0) return 'astăzi';
|
||||
if (diffDays === 1) return 'ieri';
|
||||
if (diffDays < 7) return `acum ${diffDays} zile`;
|
||||
if (diffDays < 30) return `acum ${Math.floor(diffDays / 7)} săptămâni`;
|
||||
if (diffDays < 365) return `acum ${Math.floor(diffDays / 30)} luni`;
|
||||
return `acum ${Math.floor(diffDays / 365)} ani`;
|
||||
if (diffDays === 0) return 'astăzi'
|
||||
if (diffDays === 1) return 'ieri'
|
||||
if (diffDays < 7) return `acum ${diffDays} zile`
|
||||
if (diffDays < 30) return `acum ${Math.floor(diffDays / 7)} săptămâni`
|
||||
if (diffDays < 365) return `acum ${Math.floor(diffDays / 30)} luni`
|
||||
return `acum ${Math.floor(diffDays / 365)} ani`
|
||||
}
|
||||
|
||||
export function generateExcerpt(content: string, maxLength = 160): string {
|
||||
const text = content
|
||||
.replace(/^---[\s\S]*?---/, '')
|
||||
.replace(/!\[.*?\]\(.*?\)/g, '')
|
||||
.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1')
|
||||
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
||||
.replace(/[#*`]/g, '')
|
||||
.trim();
|
||||
.trim()
|
||||
|
||||
if (text.length <= maxLength) return text;
|
||||
if (text.length <= maxLength) return text
|
||||
|
||||
const truncated = text.slice(0, maxLength);
|
||||
const lastSpace = truncated.lastIndexOf(' ');
|
||||
return truncated.slice(0, lastSpace) + '...';
|
||||
const truncated = text.slice(0, maxLength)
|
||||
const lastSpace = truncated.lastIndexOf(' ')
|
||||
return truncated.slice(0, lastSpace) + '...'
|
||||
}
|
||||
|
||||
export function generateSlug(title: string): string {
|
||||
const romanianMap: Record<string, string> = {
|
||||
'ă': 'a', 'â': 'a', 'î': 'i', 'ș': 's', 'ț': 't',
|
||||
'Ă': 'a', 'Â': 'a', 'Î': 'i', 'Ș': 's', 'Ț': 't'
|
||||
};
|
||||
ă: 'a',
|
||||
â: 'a',
|
||||
î: 'i',
|
||||
ș: 's',
|
||||
ț: 't',
|
||||
Ă: 'a',
|
||||
Â: 'a',
|
||||
Î: 'i',
|
||||
Ș: 's',
|
||||
Ț: 't',
|
||||
}
|
||||
|
||||
return title
|
||||
.split('')
|
||||
@@ -49,5 +67,5 @@ export function generateSlug(title: string): string {
|
||||
.join('')
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
.replace(/^-+|-+$/g, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user