Skip to content

Commit

Permalink
Merge pull request #55 from bjcarlson42/github-followers
Browse files Browse the repository at this point in the history
fix: github followers 100 limit and blog search bar.
  • Loading branch information
bjcarlson42 authored Dec 28, 2021
2 parents a07b3ac + c6e310b commit e3e6562
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 21 additions & 4 deletions pages/api/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ export default async (req, res) => {
"Authorization": "Token " + process.env.GITHUB_KEY
}
// followers
const url = "https://api.github.com/users/bjcarlson42/followers?per_page=1000"
const response = await fetch(url, { "headers": headers })
const json = await response.json()
const numFollwers = Object.keys(json).length
let url = "https://api.github.com/users/bjcarlson42/followers?per_page=100&page=1" // each page has 100 followers

// fetch followers from url and repeat until a page with no followers is found
let numFollwers = 0
let page = 1

while (true) {
const response = await fetch(url, {
headers
})
const json = await response.json()
numFollwers += json.length

if (json.length === 0) {
break
}

page++
url = `https://api.github.com/users/bjcarlson42/followers?per_page=100&page=${page}`
}

// projects
const url2 = "https://api.github.com/users/bjcarlson42/repos?per_page=1000"
const response2 = await fetch(url2, { "headers": headers })
Expand Down
8 changes: 4 additions & 4 deletions pages/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export default function Blog({ posts }) {
(a, b) =>
Number(new Date(b.publishedAt)) - Number(new Date(a.publishedAt))
)
// .filter((frontMatter) =>
// frontMatter?.title?.toLowerCase()?.includes(searchValue?.toLowerCase()) ||
// frontMatter?.summary?.toLowerCase()?.includes(searchValue?.toLowerCase())
// )
.filter((frontMatter) =>
frontMatter.data?.title?.toLowerCase()?.includes(searchValue.toLowerCase()) ||
frontMatter.data?.summary?.toLowerCase()?.includes(searchValue.toLowerCase())
)

return (
<>
Expand Down

1 comment on commit e3e6562

@vercel
Copy link

@vercel vercel bot commented on e3e6562 Dec 28, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.