import type { BlogArticle } from "../types";
export const useBlog = () => {
const articles = useState<BlogArticle[]>("articles", () => []);
const featuredArticles = useState<BlogArticle[]>("featured", () => []);
const {
locale: { value: localCode },
} = useI18n();
let collection_name = "blog";
if (localCode === "fr") {
collection_name = "blogfr";
}
async function fetchList() {
try {
const { data } = await useAsyncData("blog-list", () => {
return queryCollection(collection_name)
.where("extension", "=", "md")
.order("date", "DESC")
.all();
});
articles.value = data.value;
featuredArticles.value = articles.value
?.filter((obj) => obj.featured)
.slice(0, 1);
} catch (e) {
articles.value = [];
featuredArticles.value = [];
return e;
}
}
return {
articles,
featuredArticles,
fetchList,
};
};
import type { BlogArticle } from "../types";
export const useBlog = () => {
const articles = useState<BlogArticle[]>("articles", () => []);
const featuredArticles = useState<BlogArticle[]>("featured", () => []);
const {
locale: { value: localCode },
} = useI18n();
let collection_name = "blog";
if (localCode === "fr") {
collection_name = "blogfr";
}
async function fetchList() {
try {
const { data } = await useAsyncData("blog-list", () => {
return queryCollection(collection_name)
.where("extension", "=", "md")
.order("date", "DESC")
.all();
});
articles.value = data.value;
featuredArticles.value = articles.value
?.filter((obj) => obj.featured)
.slice(0, 1);
} catch (e) {
articles.value = [];
featuredArticles.value = [];
return e;
}
}
return {
articles,
featuredArticles,
fetchList,
};
};