Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show dev.to posts command #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"ascii": "liveterm",
"social": {
"github": "github",
"linkedin": "linkedin"
"linkedin": "linkedin",
"devToUsername": "Dev.to Username"
},
"email": "[email protected]",
"ps1_hostname": "liveterm",
Expand Down
7 changes: 7 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
14 changes: 14 additions & 0 deletions src/utils/bin/api_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
const projects = await getProjects();
Expand Down Expand Up @@ -34,3 +35,16 @@ export const weather = async (args: string[]): Promise<string> => {
const weather = await getWeather(city);
return weather;
};

export const posts = async (args: string[]): Promise<string> => {
const posts = await getPostsDevTo();
if (posts.length) {
return `My Latest posts on Dev.To:<br>${posts
.map(
(post) =>
` - <a class="text-light-blue dark:text-dark-blue underline" href="${post.url}" target="_blank">${post.title}</a>`,
).join('\n')}`;
} else {
return `I don't have any posts on Dev.to yet :(`;
}
};