Todas las fuentes
Dev.to
Desarrollo v1.0.0Top articles from Dev.to developer community
@codytseng #dev #articles #programming
Configuración
| Nombre | Clave | Tipo | Requerido | Predeterminado | Descripción |
|---|---|---|---|---|---|
| Tag | TAG | string | No | — | Filter by tag, comma-separated for multiple (e.g., javascript,python,webdev). Leave empty for all tags. |
Código fuente
version: 1.0.0
name: Dev.to
description: Top articles from Dev.to developer community
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
- dev
- articles
- programming
config:
- key: TAG
name: Tag
type: string
required: false
description: Filter by tag, comma-separated for multiple (e.g., javascript,python,webdev). Leave empty for all tags. version: 1.0.0
name: Dev.to
description: Top articles from Dev.to developer community
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
- dev
- articles
- programming
config:
- key: TAG
name: Tag
type: string
required: false
description: Filter by tag, comma-separated for multiple (e.g., javascript,python,webdev). Leave empty for all tags. import type { GlancewayAPI, SourceMethods } from "../../types";
export default (api: GlancewayAPI): SourceMethods => {
return {
async refresh() {
type Article = {
id: number;
title: string;
description: string;
url: string;
published_at: string;
positive_reactions_count: number;
comments_count: number;
reading_time_minutes: number;
user: { name: string };
};
const tagConfig = api.config.get("TAG");
const tags = tagConfig
? tagConfig.split(",").map((t) => t.trim()).filter(Boolean)
: [];
const toItems = (articles: Article[]) =>
articles.map((article) => ({
id: article.id.toString(),
title: article.title,
subtitle: article.description || `${article.positive_reactions_count} reactions · ${article.comments_count} comments`,
url: article.url,
timestamp: article.published_at,
}));
if (tags.length > 0) {
const perPage = Math.min(30, Math.floor(150 / tags.length));
await Promise.all(
tags.map(async (tag) => {
const res = await api.fetch<Article[]>(
`https://dev.to/api/articles?per_page=${perPage}&top=7&tag=${encodeURIComponent(tag)}`,
);
if (res.ok && res.json) {
api.emit(toItems(res.json));
}
}),
);
} else {
const res = await api.fetch<Article[]>(
"https://dev.to/api/articles?per_page=30&top=7",
);
if (res.ok && res.json) {
api.emit(toItems(res.json));
}
}
},
};
}; import type { GlancewayAPI, SourceMethods } from "../../types";
export default (api: GlancewayAPI): SourceMethods => {
return {
async refresh() {
type Article = {
id: number;
title: string;
description: string;
url: string;
published_at: string;
positive_reactions_count: number;
comments_count: number;
reading_time_minutes: number;
user: { name: string };
};
const tagConfig = api.config.get("TAG");
const tags = tagConfig
? tagConfig.split(",").map((t) => t.trim()).filter(Boolean)
: [];
const toItems = (articles: Article[]) =>
articles.map((article) => ({
id: article.id.toString(),
title: article.title,
subtitle: article.description || `${article.positive_reactions_count} reactions · ${article.comments_count} comments`,
url: article.url,
timestamp: article.published_at,
}));
if (tags.length > 0) {
const perPage = Math.min(30, Math.floor(150 / tags.length));
await Promise.all(
tags.map(async (tag) => {
const res = await api.fetch<Article[]>(
`https://dev.to/api/articles?per_page=${perPage}&top=7&tag=${encodeURIComponent(tag)}`,
);
if (res.ok && res.json) {
api.emit(toItems(res.json));
}
}),
);
} else {
const res = await api.fetch<Article[]>(
"https://dev.to/api/articles?per_page=30&top=7",
);
if (res.ok && res.json) {
api.emit(toItems(res.json));
}
}
},
};
};