Files snapshot from main

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
18e543 Tucker McKnight
a62ca2 Tucker McKnight
87bcc2 Tucker McKnight
ce6a47 Tucker McKnight
4f267d Tucker McKnight
ce6a47 Tucker McKnight
7f8822 Tucker McKnight
99f634 Tucker McKnight
7f8822 Tucker McKnight
ce6a47 Tucker McKnight
7f8822 Tucker McKnight
99f634 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
99f634 Tucker McKnight
99f634 Tucker McKnight
99f634 Tucker McKnight
99f634 Tucker McKnight
2a54fe Tucker McKnight
99f634 Tucker McKnight
99f634 Tucker McKnight
ce6a47 Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
1b6528 Tucker McKnight
1b6528 Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
073785 Tucker McKnight
927e7a Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
99f634 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
927e7a Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
073785 Tucker McKnight
87bcc2 Tucker McKnight
99f634 Tucker McKnight
90eb8e Tucker McKnight
90eb8e Tucker McKnight
18e543 Tucker McKnight
ce6a47 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
b41ce6 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
868131 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
b41ce6 Tucker McKnight
f38061 Tucker McKnight
0dfdda Tucker McKnight
f38061 Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
0f95b3 Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
f38061 Tucker McKnight
0f95b3 Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
f38061 Tucker McKnight
f38061 Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
0f95b3 Tucker McKnight
0f95b3 Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
f38061 Tucker McKnight
0dfdda Tucker McKnight
f38061 Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
ddab9d Tucker McKnight
f38061 Tucker McKnight
f38061 Tucker McKnight
f38061 Tucker McKnight
f38061 Tucker McKnight
f38061 Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
f38061 Tucker McKnight
3d1d1f Tucker McKnight
0dfdda Tucker McKnight
90eb8e Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
0dfdda Tucker McKnight
0dfdda Tucker McKnight
90eb8e Tucker McKnight
0dfdda Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
3d1d1f Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
18e543 Tucker McKnight
f8e00d Tucker McKnight
18e543 Tucker McKnight
651585 Tucker McKnight
ce6a47 Tucker McKnight
ce6a47 Tucker McKnight
4f267d Tucker McKnight
import m from 'mithril'
import { type Repository } from '../src/dataTypes.ts'
import { NavHelper } from './helpers/nav.ts'
import htmlPage from './common/htmlPage.ts'

export default async (reposConfig: any, eleventyConfig: any, data: any) => {
  const repo: Repository = data.currentRepo
  const ref: Repository['branches'][0] | Repository['tags'][0] = data.currentRef
  const renderContentIfAvailable = eleventyConfig.getFilter("renderContentIfAvailable")
  const slugify = eleventyConfig.getFilter("slugify")
  const getReadMe = eleventyConfig.getFilter("getReadMe")
  const latestCommit = repo.commits.get(ref.sha)
  const latestCommitMessage = latestCommit.message.length > 72
    ? latestCommit.message.split('\n')[0].substr(0, 72) + '...'
    : latestCommit.message

  const mostRecentCommitOverall = data.mostRecentCommitsOverall[repo.name]

  const nav = NavHelper({
    reposConfig,
    slugify,
    currentRepoName: repo.name,
    currentRefName: data.currentRef.name,
    currentRefType: data.flatRef.type,
  })

  const languageCounts = new Map<string, number>()

  const countPromises = Array.from(ref.fileList.keys()).map(async (currentFile) => {
    return new Promise<void>(async (resolve) => {
      const fileParts = currentFile.split(".")
      const fileExtension = fileParts[fileParts.length - 1]
// todo: add more ignoreable extensions or specific files
// (like package-lock.json). Allow glob patterns?
      if (fileExtension === 'gitignore') {
        resolve()
      }

      const fileLineCount = (await repo.files(currentFile, data.currentRef.sha)).contents.split('\n').length
      languageCounts.set(fileExtension, (languageCounts.get(fileExtension) + fileLineCount) || fileLineCount)
      resolve()
    })
  })

  await Promise.all(countPromises)

  let languagePercentages: Array<[string, number]> = []
  const total = Array.from(ref.fileList.keys()).length

  for (const entry of languageCounts) {
    languagePercentages.push([entry[0], entry[1] / total])
  }
  languagePercentages.sort((a, b) => {
    return b[1] - a[1]
  })

  // Show graph for the top 5 languages, unless there are fewer than 5 total
  const numOfTopLanguages = Math.min(5, languagePercentages.length)
  const topLanguagePercentages = languagePercentages.slice(0, numOfTopLanguages)
  const otherLanguagePercent = languagePercentages.slice(numOfTopLanguages).reduce((sum, current) => {
    return sum + current[1]
  }, 0)

  const largestPercent = Math.max(...topLanguagePercentages.map(tuple => tuple[1]), otherLanguagePercent)

  const readmeContent = await renderContentIfAvailable(await getReadMe(repo.name, ref.name), ref.name)
  // TODO: make dark mode work here
  const colors = reposConfig.defaultTemplate.colors.languageGraph

  const pageContent = [
    m('div', {class: "row"}, [
      m('div', {class: "col"}, [
        m('div', {class: "px-4 pt-3 bezel-header"}, [
          m('div', {class: "row"}, [
            m('div', {class: "col-12 col-lg-6"}, [
              m('h1', {class: "display-3 text-white"},
                m('em', repo.name)
              ),
              repo.description
                ? m('p', {class: "text-white fs-4 fw-light"}, repo.description)
                : null
            ]),
            m('div', {class: "col-12 col-lg-6 d-flex flex-column justify-content-around"}, [
              m('div', {class: 'row'}, [
                m('div', {class: "col-12 col-sm-6"}, [
                  m('div', {class: "row"}, [
                    m('div', {class: "col-6 col-lg-12 pb-0 pb-lg-2"}, [
                      m('div', {class: "text-white d-inline-block"}, [
                        m('div', {class: "latest-commit fs-6 fw-light"}, [
                          m('span', {class: 'me-1'}, `Latest in ${ref.name}`),
                          m('a', {href: nav.rssFeed(), class: "fw-light p-0 btn badge shadow-none"}, [
                            m('img', {
                              class: 'mb-1 me-1',
                              src: `${nav.rootPath()}frontend/img/rss-icon.svg`,
                              style: "width: 11px;"
                            }),
                            'RSS',
                          ]),
                        ]),
                        m('div', {class: "font-monospace"}, [
                          `${latestCommit.date.toDateString().split(' ').slice(1).join(' ')} `,
                          m('a', {href: nav.commit(latestCommit.hash), class: "fw-bold link-info"}, latestCommit.hash.substr(0, 6))
                        ]),
                      ])
                    ]),
                    m('div', {class: "col-6 col-lg-12 pb-3 pb-lg-0"}, [
                      m('div', {class: "text-white d-inline-block"}, [
                        m('div', {class: "latest-commit fs-6 fw-light"}, 'Latest overall'),
                        m('div', {class: "font-monospace"}, [
                          `${mostRecentCommitOverall.commit.date.toDateString().split(' ').slice(1).join(' ')} `,
                          m('a', {
                            href: nav.commit(mostRecentCommitOverall.commit.hash),
                            class: "link-info fw-bold"
                          }, mostRecentCommitOverall.commit.hash.substr(0, 6))
                        ]),
                        m('span', {class: "fs-6 fw-light"}, [
                          'in branch ',
                          m('a', {
                            href: nav.commits(1, {
                              refName: mostRecentCommitOverall.branch.name,
                              refType: 'branch',
                            }),
                            class: "link-info"
                          }, mostRecentCommitOverall.branch.name),
                        ])
                      ])
                    ])
                  ])
                ]),
                m('div', {class: "col-12 col-sm-6 d-flex"}, [
                  m('div', {class: "d-flex flex-column"}, [
                    topLanguagePercentages.map((percentTuple) => {
                      return m('div', {class: 'language-name me-1 d-flex justify-content-end align-items-end small text-white font-monospace flex-grow-1'}, percentTuple[0])
                    }),
                    otherLanguagePercent > 0
                    ? m('div', {class: 'language-name me-1 d-flex justify-content-end align-items-end small text-white font-monospace flex-grow-1'}, 'other')
                    : null
                  ]),
                  m('div', {class: "flex-grow-1 d-flex flex-column"}, [
                    topLanguagePercentages.map((percentTuple, index) => {
                      const color = colors[index % (colors.length - 1)].light
                      return m('div', {
                        class: 'language-col flex-grow-1',
                        style: `width: ${percentTuple[1] / largestPercent * 100}%; background-color: ${color};`
                      })
                    }),
                    otherLanguagePercent > 0
                      ? m('div', {
                        class: 'language-col flex-grow-1',
                        style: `width: ${otherLanguagePercent / largestPercent * 100}%; background-color: ${colors[colors.length - 1].light};`
                      })
                      : null
                  ])
                ]),
              ]),
              m('div', {class: "row align-items-center"}, [
                m('div', {class: "col-12"}, [
                  m('div', {class: "header-button-container"}, [
                    m('button', {class: "btn btn-info btn-lg dropdown-toggle clone-popover-btn"}, 'Clone'),
                    nav.homepageButtons.map((buttonConfig) => {
                      return m('a', {
                        class: "btn btn-outline-info btn-lg shadow-none",
                        href: buttonConfig.url,
                        target: buttonConfig.newTab ? "_blank" : "_self"
                      }, m.trust(buttonConfig.text + `${buttonConfig.newTab ? ' <span>&#x29C9;</span>' : ''}`))
                    })
                  ])
                ])
              ])
            ])
          ]),
          m('noscript',
            m('div', {class: "row mt-2"},
              m('div', {class: "col"},
                m('p', {class: "font-monospace text-white"},
                  `Clone URL: ${repo.cloneUrl}`
                )
              )
            )
          ),
        ])
      ])
    ]),
    m('div', {class: "row my-4 mx-1"},
      m('div', {class: "col readme"}, m.trust(readmeContent))
    )
  ]

  return await htmlPage(reposConfig, eleventyConfig, data, pageContent)
}