Skip to content

feat: api/latest-posts (#19) #21

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

Merged
merged 1 commit into from
Mar 16, 2022
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
.vercel
.vercel
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# velog-readme-stats란?
> markdown에서 나의 velog의 정보를 가져올수 있는 도구입니다.

# Velog 뱃지
> ?name= 의 값을 변경하세요
```
[![Velog's GitHub stats](https://velog-readme-stats.vercel.app/api/badge?name=eungyeole)](https://velog.io/@eungyeole)
```
[![Velog's GitHub stats](https://velog-readme-stats.vercel.app/api/badge?name=eungyeole)](https://velog.io/@eungyeole)


# 최신 글 가져오기
> ?name= 의 값을 변경하세요
Expand All @@ -27,4 +34,21 @@ Color Option
```
[![Velog's GitHub stats](https://velog-readme-stats.vercel.app/api?name=eungyeole&color=dark)](https://github.com/eungyeole/velog-readme-stats)

## 특정 제목을 가진 글
> Option : ```&slug```

```
[![Velog's GitHub stats](https://velog-readme-stats.vercel.app/api?name=eungyeole&slug=Velog-포스트로-Github를-꾸며보자)](https://github.com/eungyeole/velog-readme-stats)
```
[![Velog's GitHub stats](https://velog-readme-stats.vercel.app/api?name=eungyeole&slug=Velog-포스트로-Github를-꾸며보자)](https://github.com/eungyeole/velog-readme-stats)


## 상태카드와 최신글 연결하기
> Option : name, tag
카드클릭시 최신글로 리다이렉트 합니다.

```
https://velog-readme-stats.vercel.app/api/redirect?name=eungyeole&tag=github
```

[![Velog's GitHub stats](https://velog-readme-stats.vercel.app/api?name=eungyeole&tag=github)](https://velog-readme-stats.vercel.app/api/redirect?name=eungyeole&tag=github)
16 changes: 8 additions & 8 deletions api/badge.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const createBadge = require("../src/cards/velog-badge");

module.exports = async (req, res) => {
const { name } = req.query;
res.setHeader('Content-Type', 'image/svg+xml');
try{
return res.send(createBadge(name))
} catch(e){
return res.send(e.message)
}
}
const { name } = req.query;
res.setHeader("Content-Type", "image/svg+xml");
try {
return res.send(createBadge(name));
} catch (e) {
return res.send(e.message);
}
};
29 changes: 15 additions & 14 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const createCard = require('../src/cards/new-log');
const createCardDark = require('../src/cards/new-log-black');
const fetchPost = require('../src/fetchers/post-fetcher');
const fetchReadPost = require('../src/fetchers/readpost-fetcher');

const createCard = require("../src/cards/new-log");
const createCardDark = require("../src/cards/new-log-black");
const fetchPost = require("../src/fetchers/post-fetcher");
const fetchReadPost = require("../src/fetchers/readpost-fetcher");

module.exports = async (req, res) => {
const { name, tag, color, slug } = req.query;
res.setHeader('Content-Type', 'image/svg+xml');
try{
const post = !slug ? await fetchPost(name, tag) : await fetchReadPost(name, slug);
return res.send(color==='dark' ? createCardDark(post) : createCard(post))
} catch(e){
return res.send(e.message)
}
}
const { name, tag, color, slug } = req.query;
res.setHeader("Content-Type", "image/svg+xml");
try {
const post = !slug
? await fetchPost(name, tag)
: await fetchReadPost(name, slug);
return res.send(color === "dark" ? createCardDark(post) : createCard(post));
} catch (e) {
return res.send(e.message);
}
};
15 changes: 15 additions & 0 deletions api/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const createLatestPostsCard = require("../src/cards/latest-posts");
const fetchPosts = require("../src/fetchers/posts-fetcher");

module.exports = async (req, res) => {
const { name } = req.query;
res.setHeader("Content-Type", "image/svg+xml");
try {
console.log(name);
const posts = await fetchPosts(name);
return res.send(createLatestPostsCard(posts));
} catch (e) {
console.log(e);
return res.send(e.message);
}
};
25 changes: 13 additions & 12 deletions api/redirect.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const fetchPost = require('../src/fetchers/post-fetcher');

const fetchPost = require("../src/fetchers/post-fetcher");

module.exports = async (req, res) => {
const { name, tag } = req.query;
try{
const post = await fetchPost(name, tag);
const url = new String(`https://velog.io/@${post.user.username}/${post.url_slug}`)
res.send(`<script>window.location.href='${url}'</script>`);
return
} catch(e){
return res.send(e.message)
}
}
const { name, tag } = req.query;
try {
const post = await fetchPost(name, tag);
const url = new String(
`https://velog.io/@${post.user.username}/${post.url_slug}`
);
res.send(`<script>window.location.href='${url}'</script>`);
return;
} catch (e) {
return res.send(e.message);
}
};
Loading