added type definitions

This commit is contained in:
ferdous
2023-05-21 11:42:20 +06:00
parent 1431ce1d35
commit 41cf468580
27 changed files with 115 additions and 58 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ import { slugify } from "./utils/textConverter";
export const getTaxonomy = async (collection: string, name: string) => {
const singlePages = await getSinglePage(collection);
const taxonomyPages = singlePages.map((page) => page.data[name]);
let taxonomies = [];
let taxonomies: string[] = [];
for (let i = 0; i < taxonomyPages.length; i++) {
const categoryArray = taxonomyPages[i];
for (let j = 0; j < categoryArray.length; j++) {
@@ -20,7 +20,7 @@ export const getTaxonomy = async (collection: string, name: string) => {
export const getAllTaxonomy = async (collection: string, name: string) => {
const singlePages = await getSinglePage(collection);
const taxonomyPages = singlePages.map((page) => page.data[name]);
let taxonomies = [];
let taxonomies: string[] = [];
for (let i = 0; i < taxonomyPages.length; i++) {
const categoryArray = taxonomyPages[i];
for (let j = 0; j < categoryArray.length; j++) {
+1 -1
View File
@@ -1,6 +1,6 @@
import { formatInTimeZone } from "date-fns-tz";
const dateFormat = (date:Date | string, format:string = "dd MMM, yyyy") => {
const dateFormat = (date:Date | string, format:string = "dd MMM, yyyy"): string => {
return formatInTimeZone(date, "America/New_York", format);
};
+1 -1
View File
@@ -1,5 +1,5 @@
// content reading
const readingTime = (content: string) => {
const readingTime = (content: string): string => {
const WPS = 275 / 60;
let images = 0;
+2 -2
View File
@@ -1,7 +1,7 @@
// similer products
const similerItems = (currentItem: any, allItems: any, slug: string) => {
let categories: [] = [];
let tags: [] = [];
let categories: string[] = [];
let tags: string[] = [];
// set categories
if (currentItem.data.categories.length > 0) {
+1 -1
View File
@@ -1,6 +1,6 @@
import { slugify } from "@/lib/utils/textConverter";
const taxonomyFilter = (posts: any[], name: string, key: any) =>
const taxonomyFilter = (posts: any[], name: string, key: string) =>
posts.filter((post) =>
post.data[name].map((name: string) => slugify(name)).includes(key)
);
+4 -10
View File
@@ -7,22 +7,18 @@ marked.use({
});
// slugify
export const slugify = (content: string) => {
if (!content) return null;
export const slugify = (content: string): string => {
return slug(content);
};
// markdownify
export const markdownify = (content: string, div?:boolean) => {
if (!content) return null;
export const markdownify = (content: string, div?:boolean): string => {
return div? marked.parse(content) : marked.parseInline(content);
};
// humanize
export const humanize = (content: string) => {
if (!content) return null;
export const humanize = (content: string): string => {
return content
.replace(/^[\s_]+|[\s_]+$/g, "")
@@ -33,9 +29,7 @@ export const humanize = (content: string) => {
};
// plainify
export const plainify = (content: string) => {
if (!content) return null;
export const plainify = (content: string): string => {
const filterBrackets = content.replace(/<\/?[^>]+(>|$)/gm, "");
const filterSpaces = filterBrackets.replace(/[\r\n]\s*[\r\n]/gm, "");
const stripHTML = htmlEntityDecoder(filterSpaces);