Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Feb 8, 2024
1 parent fb4aa1c commit d1741d3
Show file tree
Hide file tree
Showing 14 changed files with 563 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Simple workflow for deploying static content to GitHub Pages.
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch.
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages.
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying.
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Build
run: deno task build

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload build directory.
path: 'build'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"deno.enable": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "denoland.vscode-deno"
}
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# projects

List of initiatives owned by the Open Source Software team.

## Development

Make sure to install Deno:
<https://deno.land/manual/getting_started/installation>.

Build the project:

```sh
deno task build
```

Build the project in development mode:

```sh
deno task dev
```

Serve the static site:

```sh
deno task serve
```

Format the project:

```sh
deno fmt
```

Lint the project:

```sh
deno lint
```

Update dependencies:

```sh
deno task udd
```

---

Maintained with 💚 by [**@acmcsufoss**](https://github.com/acmcsufoss)
19 changes: 19 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"tasks": {
"lock": "deno cache --lock=deno.lock --lock-write deps.ts",
"udd": "deno run -Ar https://deno.land/x/udd/main.ts deps.ts && deno task lock",
"build": "deno run -A main.ts",
"dev": "deno run -A --watch main.ts",
"serve": "deno run -A https://deno.land/std/http/file_server.ts build"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxFactory": "h",
"jsxImportSource": "nano_jsx"
},
"imports": {
"#/": "./",
"nano_jsx/jsx-runtime": "https://deno.land/x/[email protected]/jsx-runtime/index.ts"
},
"exclude": ["build"]
}
220 changes: 220 additions & 0 deletions deno.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export { test } from "https://deno.land/[email protected]/front_matter/mod.ts";
export { copy, expandGlob } from "https://deno.land/[email protected]/fs/mod.ts";
export { parseArgs } from "https://deno.land/[email protected]/cli/parse_args.ts";
export { extract } from "https://deno.land/[email protected]/front_matter/any.ts";
export { CSS, render } from "https://deno.land/x/[email protected]/mod.ts";
export {
h,
Helmet,
renderSSR,
} from "https://deno.land/x/[email protected]/mod.ts";
3 changes: 3 additions & 0 deletions lib/projects/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./projects.ts";
export * from "./ssr.tsx";
export * from "./walk.ts";
29 changes: 29 additions & 0 deletions lib/projects/projects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { extract, test } from "#/deps.ts";

export interface ProjectAttrs {
title?: string;
description?: string;
participants?: string[];
labels?: string[];
repository?: string;
}

export interface Project {
id: string;
md: string;
attrs?: ProjectAttrs;
}

export function parseProject(filename: string, md: string): Project {
const id = filename.replace(/\.md$/, "");
if (!test(md)) {
return { id, md };
}

const extracted = extract<ProjectAttrs>(md);
return {
id,
md: extracted.body,
attrs: extracted.attrs,
};
}
104 changes: 104 additions & 0 deletions lib/projects/ssr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { CSS, h, Helmet, render, renderSSR } from "#/deps.ts";
import type { Project } from "./projects.ts";

/**
* makeRepositoryURL returns a URL for the given repository.
* The given repository string may be a URL or a repository name.
* If the given repository is a URL, it is returned as is.
* If the given repository is a repository name, it is converted to a URL
* by assuming the repository is owned by the acmcsufoss organization.
*/
function makeRepositoryURL(repository: string) {
if (repository.startsWith("https://")) {
return repository;
}

return `https://github.com/acmcsufoss/${repository}`;
}

function ProjectPageComponent(props: { project: Project }) {
const html = render(props.project.md, { baseUrl: "/" });
return (
<main>
<Helmet>
<html lang="en" amp />
<title>
{props.project.attrs?.title} - Open Source Software projects
</title>
<meta
name="description"
content={props.project.attrs?.description}
/>
<style>{CSS}</style>
</Helmet>

<article
className="markdown-content"
dangerouslySetInnerHTML={{ __html: html }}
/>
</main>
);
}

function ProjectPreviewComponent(props: { project: Project }) {
return (
<article>
<h1>
<a href={`/${props.project.id}.html`}>{props.project.attrs?.title}</a>
</h1>
<p>{props.project.attrs?.description}</p>
</article>
);
}

function ProjectPreviewListComponent(props: { projects: Project[] }) {
return (
<ul>
{props.projects.map((project) => (
<li>
<ProjectPreviewComponent project={project} />
</li>
))}
</ul>
);
}

export function ProjectsPageComponent(props: { projects: Project[] }) {
return (
<main>
<Helmet>
<html lang="en" amp />
<title>Open Source Software projects</title>
<meta
name="description"
content="List of initiatives owned by the Open Source Software team."
/>
</Helmet>
<ProjectPreviewListComponent projects={props.projects} />
</main>
);
}

// deno-lint-ignore no-explicit-any
function renderPageHTML(component: any) {
const html = renderSSR(component);
const { body, head, footer, attributes } = Helmet.SSR(html);
return `<!DOCTYPE html>
<html ${attributes.html.toString()}>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
${head.join("\n")}
</head>
<body ${attributes.body.toString()}>${body}${footer.join("\n")}</body>
</html>`;
}

export function renderProjectsPageHTML(projects: Project[]) {
return renderPageHTML(<ProjectsPageComponent projects={projects} />);
}

export function renderProjectPageHTML(project: Project) {
return renderPageHTML(<ProjectPageComponent project={project} />);
}
9 changes: 9 additions & 0 deletions lib/projects/walk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expandGlob } from "#/deps.ts";
import { parseProject } from "./projects.ts";

export async function* walkProjects(glob: string | URL) {
for await (const stat of expandGlob(glob)) {
const md = await Deno.readTextFile(stat.path);
yield parseProject(stat.name, md);
}
}
49 changes: 49 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { copy, parseArgs } from "#/deps.ts";
import type { Project } from "#/lib/projects/mod.ts";
import {
renderProjectPageHTML,
renderProjectsPageHTML,
walkProjects,
} from "#/lib/projects/mod.ts";

// Build script for generating static site from markdown files
// in the projects directory.
async function main(args: string[]) {
const flags = parseArgs(args, {
string: ["indir", "outdir", "staticdir"],
alias: {
indir: ["i"],
outdir: ["o"],
staticdir: ["s"],
},
default: {
indir: "projects",
outdir: "build",
staticdir: "static",
},
});

// Create outdir if it does not exist.
await Deno.mkdir(flags.outdir, { recursive: true });

// Render markdown files to HTML.
const projects: Project[] = [];
for await (const project of walkProjects(`${flags.indir}/*.md`)) {
projects.push(project);
const html = renderProjectPageHTML(project);
await Deno.writeTextFile(`${flags.outdir}/${project.id}.html`, html);
const json = JSON.stringify(project, null, 2);
await Deno.writeTextFile(`${flags.outdir}/${project.id}.json`, json);
}

// Copy contents of static directory to outdir.
await copy(flags.staticdir, flags.outdir, { overwrite: true });

// Render index page.
const html = await renderProjectsPageHTML(projects);
await Deno.writeTextFile(`${flags.outdir}/index.html`, html);
}

if (import.meta.main) {
await main(Deno.args);
}
15 changes: 15 additions & 0 deletions projects/crying-counter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "Crying Counter"
participants: ["Ethan", "Karni", "Jacob", "Justin", "Vamsi"]
labels: ["python"]
---

# Crying Counter

## Description

Counts instances of “I’m crying” by Discord user ID.

## References

- [Design document](https://docs.google.com/document/d/1G3jYfibJuN2NPhCEEtuYVbyL_C04p8puD6ynT8I7Vy8/edit)
Binary file added static/favicon.ico
Binary file not shown.

0 comments on commit d1741d3

Please sign in to comment.