Skip to content

Commit

Permalink
docs: move API calls to sveltekit instead of node
Browse files Browse the repository at this point in the history
  • Loading branch information
saadeghi committed Apr 28, 2024
1 parent 4b8d296 commit 530e989
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
runtime: ${{ inputs.runtime || 'bun'}}
LEMONSQUEEZY_API_KEY: ${{ secrets.LEMONSQUEEZY_API_KEY }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
GH_API_KEY: ${{ secrets.GH_API_KEY }}
daisyuiversion: ${{ inputs.daisyuiversion || 'latest' }}
if: |
github.event_name == 'workflow_dispatch' ||
Expand Down
12 changes: 6 additions & 6 deletions src/docs/src/lib/scripts/get-json.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { exec } from "child_process"

const commands = [
"node src/lib/scripts/download-file.js 'https://api.npmjs.org/downloads/point/2000-01-01:2100-01-01/daisyui' 'src/lib/json/npm-downloads.json'",
"node src/lib/scripts/download-file.js 'https://api.github.com/repos/saadeghi/daisyui' 'src/lib/json/github-repo.json'",
"node src/lib/scripts/download-file.js 'https://api.github.com/repos/saadeghi/daisyui/contributors?page=1&per_page=100' 'src/lib/json/github-contributors-1.json'",
"node src/lib/scripts/download-file.js 'https://api.github.com/repos/saadeghi/daisyui/contributors?page=2&per_page=100' 'src/lib/json/github-contributors-2.json'",
"node src/lib/scripts/download-file.js 'https://opencollective.com/daisyui.json' 'src/lib/json/opencollective-info.json'",
"node src/lib/scripts/download-file.js 'https://opencollective.com/daisyui/members/all.json' 'src/lib/json/opencollective-members.json'",
// "node src/lib/scripts/download-file.js 'https://api.npmjs.org/downloads/point/2000-01-01:2100-01-01/daisyui' 'src/lib/json/npm-downloads.json'",
// "node src/lib/scripts/download-file.js 'https://api.github.com/repos/saadeghi/daisyui' 'src/lib/json/github-repo.json'",
// "node src/lib/scripts/download-file.js 'https://api.github.com/repos/saadeghi/daisyui/contributors?page=1&per_page=100' 'src/lib/json/github-contributors-1.json'",
// "node src/lib/scripts/download-file.js 'https://api.github.com/repos/saadeghi/daisyui/contributors?page=2&per_page=100' 'src/lib/json/github-contributors-2.json'",
// "node src/lib/scripts/download-file.js 'https://opencollective.com/daisyui.json' 'src/lib/json/opencollective-info.json'",
// "node src/lib/scripts/download-file.js 'https://opencollective.com/daisyui/members/all.json' 'src/lib/json/opencollective-members.json'",
"node src/lib/scripts/get-youtube-resources.js 'src/lib/json/youtube.json'",
]
let number_of_files = 0
Expand Down
67 changes: 51 additions & 16 deletions src/docs/src/routes/(docs)/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,72 @@
import { GH_API_KEY } from "$env/static/private"
import depGraphCount from "dep-graph-count"
import githubRepoInfo from "$lib/json/github-repo.json"
import npmDownloadsInfo from "$lib/json/npm-downloads.json"
import contributors1 from "$lib/json/github-contributors-1.json"
import contributors2 from "$lib/json/github-contributors-2.json"
import openCollectiveBackers from "$lib/json/opencollective-members.json"
import { tweets } from "$lib/data/testimonials.js"
import { stats } from "$lib/data/stats.js"

let stargazers_count = 25000
let npmInstalls = 8000000
let stargazers_count = 30000
let npmInstalls = 13000000
let contributors = []
let backers = []

export async function load() {
let githubDeps = await depGraphCount("saadeghi", "daisyui")

if (githubRepoInfo && githubRepoInfo.stargazers_count) {
stargazers_count = githubRepoInfo.stargazers_count
const npmDownloadsInfo = await fetch(
"https://api.npmjs.org/downloads/point/2000-01-01:2100-01-01/daisyui",
{}
)

if (npmDownloadsInfo.ok) {
let data = await npmDownloadsInfo.json()
npmInstalls = data.downloads
} else {
console.error("Warning: Could not fetch npm download counts. Using default value")
}

if (npmDownloadsInfo && npmDownloadsInfo.downloads) {
npmInstalls = npmDownloadsInfo.downloads
const GHParams = {
headers: {
Authorization: `token ${GH_API_KEY}`,
},
}
const githubRepoInfo = await fetch("https://api.github.com/repos/saadeghi/daisyui", GHParams)
if (githubRepoInfo.ok) {
let data = await githubRepoInfo.json()
stargazers_count = data.stargazers_count
} else {
console.error("Warning: Could not fetch github stargazers count. Using default value")
}

if (Array.isArray(contributors1) && Array.isArray(contributors2)) {
contributors = contributors1.concat(contributors2)
const contributors1 = await fetch(
"https://api.github.com/repos/saadeghi/daisyui/contributors?page=1&per_page=100",
GHParams
)
if (contributors1.ok) {
contributors = await contributors1.json()
} else {
console.error("Warning: Could not fetch github contributors.")
}

if (Array.isArray(openCollectiveBackers)) {
backers = openCollectiveBackers.filter(
(obj, index) => openCollectiveBackers.findIndex((item) => item.name === obj.name) === index
const contributors2 = await fetch(
"https://api.github.com/repos/saadeghi/daisyui/contributors?page=2&per_page=100",
GHParams
)
if (contributors2.ok) {
contributors = contributors.concat(await contributors2.json())
} else {
console.error("Warning: Could not fetch github contributors.")
}

const openCollectiveBackers = await fetch("https://opencollective.com/daisyui/members/all.json")

if (openCollectiveBackers.ok) {
backers = await openCollectiveBackers.json()
backers = backers.filter(
(obj, index) => backers.findIndex((item) => item.name === obj.name) === index
)
} else {
console.error("Warning: Could not fetch open collective backers.")
}

// filter unused data
contributors = contributors.map(({ login, avatar_url }) => ({ login, avatar_url }))
backers = backers.map(({ name, image }) => ({ name, image }))
Expand Down

0 comments on commit 530e989

Please sign in to comment.