index.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Github } from '@/app/components/base/icons/src/public/common'
  2. import type { GithubRepo } from '@/models/common'
  3. const getStar = async () => {
  4. const res = await fetch('https://api.github.com/repos/langgenius/dify')
  5. if (!res.ok)
  6. throw new Error('Failed to fetch data')
  7. return res.json()
  8. }
  9. const GithubStar = async () => {
  10. let githubRepo: GithubRepo = { stargazers_count: 0 }
  11. if (process.env.NODE_ENV === 'development')
  12. return null
  13. try {
  14. githubRepo = await getStar()
  15. }
  16. catch (e) {
  17. return null
  18. }
  19. return (
  20. <a
  21. href='https://github.com/langgenius/dify'
  22. target='_blank'
  23. className='flex items-center leading-[18px] border border-gray-200 rounded-md text-xs text-gray-700 font-semibold overflow-hidden'>
  24. <div className='flex items-center px-2 py-1 bg-gray-100'>
  25. <Github className='mr-1 w-[18px] h-[18px]' />
  26. Star
  27. </div>
  28. <div className='px-2 py-1 bg-white border-l border-gray-200'>{`${githubRepo.stargazers_count}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}</div>
  29. </a>
  30. )
  31. }
  32. export default GithubStar