36 lines
931 B
TypeScript
36 lines
931 B
TypeScript
export const formatDate = (date: string) => {
|
|
if (!date) return null;
|
|
const [day, month, year] = date.split(".");
|
|
const d = new Date(`${year}-${month}-${day}`);
|
|
return d.toLocaleDateString("en-US", {
|
|
month: "long",
|
|
day: "numeric",
|
|
year: "numeric",
|
|
});
|
|
};
|
|
|
|
export const generateSlug = (str: string) => {
|
|
str = str?.replace(/^\s+|\s+$/g, "");
|
|
str = str?.toLowerCase();
|
|
const from = "àáãäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
|
const to = "aaaaaeeeeiiiioooouuuunc------";
|
|
|
|
for (let i = 0, l = from.length; i < l; i++) {
|
|
str = str.replace(new RegExp(from.charAt(i), "g"), to.charAt(i));
|
|
}
|
|
|
|
str = str
|
|
?.replace(/[^a-z0-9 -]/g, "")
|
|
.replace(/\s+/g, "-")
|
|
.replace(/-+/g, "-");
|
|
|
|
return str;
|
|
};
|
|
|
|
export const readingTime = (content: string) => {
|
|
const wpm = 225;
|
|
const words = content.trim().split(/\s+/).length;
|
|
const time = Math.ceil(words / wpm);
|
|
return time;
|
|
};
|