docs: move API calls to sveltekit instead of node

pull/3010/head
Pouya Saadeghi 1 month ago
parent 4b8d296f40
commit 530e989aed
  1. 1
      .github/workflows/deploy-docs.yml
  2. 12
      src/docs/src/lib/scripts/get-json.js
  3. 67
      src/docs/src/routes/(docs)/+page.server.js

@ -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' ||

@ -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

@ -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 }))

Loading…
Cancel
Save