diff --git a/config.json b/config.json index d1fa47c..5d05051 100644 --- a/config.json +++ b/config.json @@ -5,7 +5,8 @@ "ascii": "liveterm", "social": { "github": "github", - "linkedin": "linkedin" + "linkedin": "linkedin", + "devToUsername": "Dev.to Username" }, "email": "contact@email.com", "ps1_hostname": "liveterm", diff --git a/src/utils/api.ts b/src/utils/api.ts index 6840cac..82c3faf 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -28,3 +28,10 @@ export const getQuote = async () => { quote: `“${data.content}” — ${data.author}`, }; }; + +export const getPostsDevTo = async () => { + const { data } = await axios.get( + `https://dev.to/api/articles?username=${config.social.devToUsername}`, + ); + return data; +}; diff --git a/src/utils/bin/api_commands.ts b/src/utils/bin/api_commands.ts index ce4d487..340ee73 100644 --- a/src/utils/bin/api_commands.ts +++ b/src/utils/bin/api_commands.ts @@ -4,6 +4,7 @@ import { getProjects } from '../api'; import { getQuote } from '../api'; import { getReadme } from '../api'; import { getWeather } from '../api'; +import { getPostsDevTo } from '../api'; export const projects = async (args: string[]): Promise => { const projects = await getProjects(); @@ -34,3 +35,16 @@ export const weather = async (args: string[]): Promise => { const weather = await getWeather(city); return weather; }; + +export const posts = async (args: string[]): Promise => { + const posts = await getPostsDevTo(); + if (posts.length) { + return `My Latest posts on Dev.To:
${posts + .map( + (post) => + ` - ${post.title}`, + ).join('\n')}`; + } else { + return `I don't have any posts on Dev.to yet :(`; + } +}; \ No newline at end of file