Skip to content
6 changes: 6 additions & 0 deletions lib/routes/archdaily/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'ArchDaily',
url: 'archdaily.com',
};
55 changes: 55 additions & 0 deletions lib/routes/archdaily/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/search/:category?/:search',
categories: ['journal'],
example: '/archdaily/search/projects/Urban Design',
parameters: { category: 'The category to search in, including "all", "projects", "products", "images", "professionals", "article-archive", "folders", "articles"', search: 'The search query' },
features: {
requireConfig: false,
},
radar: [
{
source: ['www.archdaily.com/search/:category?q=:search'],
target: '/search/:category/:search',
},
],
name: 'Search',
maintainers: ['Friday_Anubis'],
handler,
};

async function handler(ctx) {
const { category = 'all', search } = ctx.req.param();

const baseUrl = 'https://www.archdaily.com';
const allowedCategories = new Set(['all', 'projects', 'products', 'images', 'professionals', 'article-archive', 'folders', 'articles']);
const finalCategory = allowedCategories.has(category) ? category : 'all';

const response = await ofetch<{ results?: any[] }>(`${baseUrl}/search/api/v1/us/${finalCategory}?q=${encodeURIComponent(search)}`);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const items = (response?.results ?? []).map((item) => {
const title = item?.title || item?.name;
const link = item?.url;
const image = item?.featured_images?.url_large || item?.featured_images?.url_medium || item?.featured_images?.url_small;
const category = (item?.tags ?? []).map((tag) => tag?.name).filter(Boolean);

return {
title,
link,
description: `${image ? `<img src="${image}"><br>` : ''}${item?.meta_description ?? ''}`,
pubDate: item?.publication_date ? parseDate(item.publication_date) : undefined,
author: item?.author?.name,
category,
};
});

return {
title: `ArchDaily - ${search}${finalCategory === 'all' ? '' : ` in ${finalCategory}`}`,
link: `${baseUrl}/search/${finalCategory}?q=${encodeURIComponent(search)}`,
description: `Search results for "${search}" on ArchDaily`,
item: items,
};
}
Loading