Skip to content

Commit

Permalink
update website
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Sep 13, 2023
1 parent 09d5191 commit 9a78584
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 38 deletions.
16 changes: 16 additions & 0 deletions internal/pkg/handlers/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ func RepoStatsPage(c *fiber.Ctx) error {
})
}

func RepoMaintainerPage(c *fiber.Ctx) error {
owner, repo := getOwnerAndRepo(c)
linux, windows, macos, err := getInstallationCountPerPlatform(owner, repo)
if err != nil {
return err
}
return c.Render("repo-maintainer.gohtml", map[string]any{
"Windows": windows,
"Linux": linux,
"MacOS": macos,
"Total": linux + windows + macos,
"Owner": owner,
"Repo": repo,
})
}

type Stat struct {
Owner string
Repo string
Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ func main() {
shieldsIOAPIV1.Get("/stats/total", handlers.AllStatsTotalBadge)

// Stats
// - Stats landing page
app.Get("/stats", handlers.AllStatsPage)
app.Get("/stats/:any", func(ctx *fiber.Ctx) error { return ctx.SendStatus(404) })
// - Legacy redirect
app.Get("/stats/:user/:repo", handlers.RedirectLegacyStats) // Legacy redirect
app.Get("/:user/:repo", handlers.RepoStatsPage)
app.Get("/stats/:user/:repo", handlers.RedirectLegacyStats)
app.Get("/:user/:repo/maintainer", handlers.RepoMaintainerPage)

// Installation script generator
app.Get("/:user/:repo/:os", handlers.Installation)
Expand Down
121 changes: 121 additions & 0 deletions templates/repo-maintainer.gohtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{{template "base" .}}

{{define "title"}}Maintainer view for {{.Owner}}/{{.Repo}}{{end}}

{{ define "content"}}
<header>
<hgroup>
<h1>
Maintainer view for
<a href="https://github.com/{{.Owner}}/{{.Repo}}">github.com/{{.Owner}}/{{.Repo}}</a>
</h1>
<p><a href="/{{.Owner}}/{{.Repo}}">User view</a></p>
</hgroup>
</header>
<article>
<blockquote>
This is the maintainer view for
<a href="https://github.com/{{.Owner}}/{{.Repo}}">github.com/{{.Owner}}/{{.Repo}}</a>.
If you are not a maintainer of the repository, you might find the
<a href="/{{.Owner}}/{{.Repo}}">user view</a> more interesting.
</blockquote>

<h2>Badges</h2>
<label for="badge-style">Style</label>
<select id="badge-style">
<option value="flat">flat</option>
<option value="flat-square">flat-square</option>
<option value="for-the-badge" selected>for-the-badge</option>
<option value="social">social</option>
</select>

<hgroup>
<h3>Install with instl.sh</h3>
<p>
<a href="/{{.Owner}}/{{.Repo}}">
<img class="badge" alt="install with instl.sh"
src="https://img.shields.io/badge/install_with-instl.sh-blue?link=https://instl.sh/{{.Owner}}/{{.Repo}}&style=for-the-badge"/>
</a>
</p>
</hgroup>
<pre class="badge-source"><code>[![install with instl.sh](https://img.shields.io/badge/install_with-instl.sh-blue?link=https://instl.sh/{{.Owner}}/{{.Repo}}&style=for-the-badge)](https://instl.sh/{{.Owner}}/{{.Repo}})</code></pre>

<hgroup>
<h3>Installation count</h3>
<p>
<a href="/{{.Owner}}/{{.Repo}}">
<img class="badge" alt="install count"
src="https://img.shields.io/endpoint?url=https://instl.sh/api/v1/badge/shields.io/stats/{{.Owner}}/{{.Repo}}&style=for-the-badge"/>
</a>
</hgroup>
<pre class="badge-source"><code>[![install count](https://img.shields.io/endpoint?url=https://instl.sh/api/v1/badge/shields.io/stats/{{.Owner}}/{{.Repo}}&style=for-the-badge)](https://instl.sh/{{.Owner}}/{{.Repo}})</code></pre>

<h2>Installation Commands</h2>

<h3>Table</h3>
<pre><code>
| Platform | Command |
| -------- | ------- |
| Windows | <code>iwr instl.sh/{{.Owner}}/{{.Repo}}/windows | iex</code> |
| macOS | <code>curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/macos | bash</code> |
| Linux | <code>curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/linux | bash</code> |

> [📊 Install stats](https://instl.sh/{{.Owner}}/{{.Repo}})
</code></pre>

<h3>Headings</h3>
<pre><code>
#### Windows
```powershell
iwr instl.sh/{{.Owner}}/{{.Repo}}/windows | iex
```

#### macOS
```bash
curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/macos | bash
```

#### Linux
```bash
curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/linux | bash
```

> [📊 Install stats](https://instl.sh/{{.Owner}}/{{.Repo}})
</code></pre>

</article>

<script lang="js">
async function fetchGitHubRepoDescription(username, repoName) {
const url = `https://api.github.com/repos/${username}/${repoName}`;

try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
return data.description;
} else {
console.error(`Failed to fetch data: ${response.statusText}`);
return null;
}
} catch (error) {
console.error(`An error occurred: ${error}`);
return null;
}
}

document.getElementById('badge-style').addEventListener('change', (event) => {
const style = event.target.value;
const badges = document.getElementsByClassName('badge');
for (const badge of badges) {
badge.src = badge.src.replace(/style=[^&\)]*/, `style=${style}`);
}

const badgeSources = document.getElementsByClassName('badge-source');
for (const badgeSource of badgeSources) {
const code = badgeSource.querySelector('code');
code.textContent = code.textContent.replace(/style=[^&\)]*/, `style=${style}`);
}
});
</script>
{{end}}
43 changes: 8 additions & 35 deletions templates/repo.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<header>
<hgroup>
<h1>Installer for <a href="https://github.com/{{.Owner}}/{{.Repo}}">github.com/{{.Owner}}/{{.Repo}}</a></h1>
<p id="repo-desc"></p>
<p aria-busy="true" id="repo-desc"></p>
</hgroup>
</header>
<article>
Expand Down Expand Up @@ -62,48 +62,21 @@
</table>

<hgroup>
<h2>Markdown</h2>
<p>Markdown presets for your <code>README</code>!</p>
<h2>Maintainer</h2>
<p>Maintaining {{.Owner}}/{{.Repo}}?</p>
</hgroup>

<h3>Table</h3>
<pre><code>
| Platform | Command |
| -------- | ------- |
| Windows | <code>iwr instl.sh/{{.Owner}}/{{.Repo}}/windows | iex</code> |
| macOS | <code>curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/macos | bash</code> |
| Linux | <code>curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/linux | bash</code> |

> [📊 Install stats](https://instl.sh/{{.Owner}}/{{.Repo}})
</code></pre>

<h3>Headings</h3>
<pre><code>
#### Windows
```powershell
iwr instl.sh/{{.Owner}}/{{.Repo}}/windows | iex
```

#### macOS
```bash
curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/macos | bash
```

#### Linux
```bash
curl -sSL instl.sh/{{.Owner}}/{{.Repo}}/linux | bash
```

> [📊 Install stats](https://instl.sh/{{.Owner}}/{{.Repo}})
</code></pre>

<p>
If you are a maintainer of <a href="https://github.com/{{.Owner}}/{{.Repo}}">github.com/{{.Owner}}/{{.Repo}}</a>,
you can check out the <a href="/{{.Owner}}/{{.Repo}}/maintainer">maintainer page of this repo</a> for
customized badges and Markdown snippets.
</article>

<script lang="js">
fetchGitHubRepoDescription('{{.Owner}}', '{{.Repo}}')
.then(description => {
if (description) {
document.getElementById('repo-desc').textContent = description;
document.getElementById('repo-desc').removeAttribute('aria-busy');
}
});

Expand Down

0 comments on commit 9a78584

Please sign in to comment.