init commit

This commit is contained in:
ryanchristo 2026-11-17 18:44:03 -08:00
commit c0ee8a4a11
No known key found for this signature in database
54 changed files with 1055 additions and 0 deletions

24
.eslintrc.json Normal file
View file

@ -0,0 +1,24 @@
{
"plugins": ["react"],
"extends": [
"eslint:recommended",
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"@typescript-eslint/no-explicit-any": "off"
},
"settings": {
"react": {
"version": "detect"
}
}
}

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.next
dist
node_modules

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "artifacts"]
path = artifacts
url = https://github.com/chora-io/artifacts

4
.prettierrc Normal file
View file

@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# website
chora website

View file

@ -0,0 +1,11 @@
.page {
composes: page from '../../../../styles/page.css';
}
.banner {
composes: banner-document from '../../../../styles/banner.css';
}
.content {
composes: content-full from '../../../../styles/content.css';
}

View file

@ -0,0 +1,35 @@
import { Metadata } from 'next'
import { getArtifact, getArtifacts } from '@utils'
import styles from './page.module.css'
export const metadata: Metadata = {
title: 'chora studio | research',
}
export const generateStaticParams = () => {
return getArtifacts('choreography')
}
const ArtifactPage = async ({ params }: any) => {
const artifact = await getArtifact('choreography', params.id)
return (
<div className={styles.page}>
<div className={styles.banner}>
<div>
<p>{`author: ${artifact.author}`}</p>
<p>{`title: ${artifact.title}`}</p>
<p>{`description: ${artifact.description}`}</p>
<p>{`created: ${artifact.created.toDateString()}`}</p>
<p>{`updated: ${artifact.updated.toDateString()}`}</p>
</div>
</div>
<div className={styles.content}>
<div dangerouslySetInnerHTML={{ __html: artifact.content }} />
</div>
</div>
)
}
export default ArtifactPage

View file

@ -0,0 +1,24 @@
.page {
composes: page from '../../styles/page.css';
}
.banner {
composes: banner from '../../styles/banner.css';
}
.content {
composes: content-full from '../../styles/content.css';
}
.content ul {
list-style: none inside none;
}
.content li {
margin: 2em 0;
}
.content p {
color: var(--color-text);
font-weight: 300;
}

65
app/artifacts/page.tsx Normal file
View file

@ -0,0 +1,65 @@
import { Metadata } from 'next'
import Link from 'next/link'
import { getArtifacts } from '@utils'
import styles from './page.module.css'
export const metadata: Metadata = {
title: 'chora | artifacts',
}
async function getResearchArtifacts() {
return [
{ group: 'choreography', items: getArtifacts('choreography') },
]
}
const ResearchPage = async () => {
const artifacts = await getResearchArtifacts()
return (
<div className={styles.page}>
<div className={styles.banner}>
<div>
<h1>{'artifacts'}</h1>
</div>
</div>
<div className={styles.content}>
<div>
{!artifacts.length ? (
<p>
<i>{'failed to load artifacts'}</i>
</p>
) : (
<div>
{artifacts.map(({ group, items }) => (
<div key={group} style={{ margin: '1em 0' }}>
<h2>{group}</h2>
<ul>
{items.map(
({ id, title, description, created, updated }) => (
<li key={id}>
<Link href={`/artifacts/` + group + '/' + id}>
<h3>{title}</h3>
<p>{description}</p>
<p>
<i>{`created: ${created.toDateString()}`}</i>
{' | '}
<i>{`updated: ${updated.toDateString()}`}</i>
</p>
</Link>
</li>
),
)}
</ul>
</div>
))}
</div>
)}
</div>
</div>
</div>
)
}
export default ResearchPage

196
app/globals.css Normal file
View file

@ -0,0 +1,196 @@
@font-face {
font-family: 'Ubuntu';
font-style: normal;
font-weight: normal;
src: url('../assets/font/Ubuntu-Regular.ttf');
}
@font-face {
font-family: 'Ubuntu';
font-style: italic;
font-weight: normal;
src: url('../assets/font/Ubuntu-Italic.ttf');
}
@font-face {
font-family: 'Ubuntu';
font-style: normal;
font-weight: bold;
src: url('../assets/font/Ubuntu-Bold.ttf');
}
@font-face {
font-family: 'Ubuntu';
font-style: italic;
font-weight: bold;
src: url('../assets/font/Ubuntu-BoldItalic.ttf');
}
@font-face {
font-family: 'Ubuntu';
font-style: normal;
font-weight: 300;
src: url('../assets/font/Ubuntu-Light.ttf');
}
@font-face {
font-family: 'Ubuntu';
font-style: italic;
font-weight: 300;
src: url('../assets/font/Ubuntu-LightItalic.ttf');
}
@font-face {
font-family: 'Ubuntu';
font-style: normal;
font-weight: 500;
src: url('../assets/font/Ubuntu-Medium.ttf');
}
@font-face {
font-family: 'Ubuntu';
font-style: italic;
font-weight: 500;
src: url('../assets/font/Ubuntu-MediumItalic.ttf');
}
:root {
--color-error: rgb(245, 45, 45);
--color-theme: rgb(0, 195, 165);
--font-family: 'Ubuntu', sans-serif;
--footer-height: 320px;
--header-height: 80px;
--sidebar-width: 240px;
--transition: 0.25s;
/* light theme */
--background-primary: rgb(255, 255, 255);
--background-primary-transparent: rgba(255, 255, 255, 0.98);
--background-secondary: rgb(250, 250, 250);
--background-secondary-transparent: rgba(250, 250, 250, 0.98);
--box-shadow: 0 0 4px rgb(245, 245, 245);
--box-shadow-color: rgb(245, 245, 245);
--color-text: rgb(10, 10, 10);
--color-text-placeholder: rgba(10, 10, 10, 0.5);
}
@media (max-width: 850px) {
:root {
--footer-height: 80px;
}
}
.dark-theme {
--background-primary: rgb(17, 17, 17);
--background-primary-transparent: rgba(17, 17, 17, 0.98);
--background-secondary: rgb(22, 22, 22);
--background-secondary-transparent: rgba(22, 22, 22, 0.98);
--box-shadow: 0 0 4px rgb(27, 27, 27);
--box-shadow-color: rgb(27, 27, 27);
--color-text: rgb(245, 245, 245);
--color-text-placeholder: rgba(245, 245, 245, 0.5);
}
* {
margin: 0;
padding: 0;
}
html {
cursor: default;
}
body {
color: var(--color-text);
font-family: var(--font-family);
font-weight: 300;
}
main {
overflow: hidden;
}
h1,
h2,
h3,
h4,
h5 {
font-weight: 300;
}
p {
line-height: 1.75;
}
a,
a:active {
color: var(--color-theme);
font-weight: 400;
text-decoration: none;
transition: var(--transition);
}
a:hover {
opacity: 0.75;
}
button {
background: var(--color-theme);
border: none;
border-radius: 1em;
color: var(--background-primary);
font-family: var(--font-family);
font-size: 1em;
outline: none;
transition: var(--transition);
}
button:hover {
cursor: pointer;
opacity: 0.75;
}
input,
textarea,
select {
background: var(--background-primary);
border: none;
box-shadow: var(--box-shadow);
color: var(--color-text);
font-family: var(--font-family);
outline: none;
}
textarea {
line-height: 1.5;
white-space: pre;
}
input::placeholder,
textarea::placeholder {
color: var(--color-text-placeholder);
}
pre {
overflow-x: scroll;
scrollbar-width: none; /* hide scrollbar - Firefox */
-ms-overflow-style: none; /* hide scrollbar - Internet Explorer 10+ */
}
pre::-webkit-scrollbar {
display: none; /* hide scrollbar - Safari and Chrome */
}
hr {
border: 0.05em solid var(--box-shadow-color);
}
td {
overflow-x: scroll;
scrollbar-width: none; /* hide scrollbar - Firefox */
-ms-overflow-style: none; /* hide scrollbar - Internet Explorer 10+ */
}
td::-webkit-scrollbar {
display: none; /* hide scrollbar - Safari and Chrome */
}

50
app/layout.tsx Normal file
View file

@ -0,0 +1,50 @@
'use client'
import { Background, Header, Sidebar } from 'chora/components'
import { MenuContextProvider, ThemeContextProvider } from 'chora/contexts'
import './globals.css'
const Layout = ({ children }: any) => (
<html lang="en">
<body>
<ThemeContextProvider>
<MenuContextProvider>
<Background />
<Header
title={{
link: '/',
}}
items={[
{
link: '/artifacts',
title: 'artifacts',
target: '',
},
]}
showMenuButton={true}
showMobileTitle={true}
/>
<Sidebar
items={[
{
link: '.',
target: '',
title: 'home',
},
{
link: 'artifacts',
target: '',
title: 'artifacts',
},
]}
mobileOnly={true}
/>
<main>{children}</main>
</MenuContextProvider>
</ThemeContextProvider>
</body>
</html>
)
export default Layout

3
app/not-found.module.css Normal file
View file

@ -0,0 +1,3 @@
.page {
composes: page-center-not-found from '../styles/page.css';
}

18
app/not-found.tsx Normal file
View file

@ -0,0 +1,18 @@
import { Metadata } from 'next'
import styles from './not-found.module.css'
export const metadata: Metadata = {
title: '404 | a placeless place',
}
const NotFoundPage = () => (
<div className={styles.page}>
<div>
<h1>{'404'}</h1>
<h2>{'a placeless place'}</h2>
</div>
</div>
)
export default NotFoundPage

25
app/page.module.css Normal file
View file

@ -0,0 +1,25 @@
.page {
composes: page from '../styles/page.css';
}
.banner {
composes: banner-full from '../styles/banner.css';
}
.content {
composes: content-full from '../styles/content.css';
}
.content > div {
padding: 6em 0 !important;
}
@media (max-width: 850px) {
.content > div {
padding: 4em 0 !important;
}
}
.content > div > a {
margin-bottom: 3em !important;
}

27
app/page.tsx Normal file
View file

@ -0,0 +1,27 @@
import { Metadata } from 'next'
import styles from './page.module.css'
export const metadata: Metadata = {
title: 'chora | open protocol',
}
const HomePage = () => {
return (
<div className={styles.page}>
<div className={styles.banner}>
<div>
<h1>
{'chora'}
</h1>
<p>
<i>{'a third thing or perhaps no thing'}</i>
</p>
<p>{'open protocol'}</p>
</div>
</div>
</div>
)
}
export default HomePage

1
artifacts Submodule

@ -0,0 +1 @@
Subproject commit f3ccc93ecc7f8c61a7c06c90a34d2445b331909b

96
assets/font/UFL.txt Normal file
View file

@ -0,0 +1,96 @@
-------------------------------
UBUNTU FONT LICENCE Version 1.0
-------------------------------
PREAMBLE
This licence allows the licensed fonts to be used, studied, modified and
redistributed freely. The fonts, including any derivative works, can be
bundled, embedded, and redistributed provided the terms of this licence
are met. The fonts and derivatives, however, cannot be released under
any other licence. The requirement for fonts to remain under this
licence does not require any document created using the fonts or their
derivatives to be published under this licence, as long as the primary
purpose of the document is not to be a vehicle for the distribution of
the fonts.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this licence and clearly marked as such. This may
include source files, build scripts and documentation.
"Original Version" refers to the collection of Font Software components
as received under this licence.
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to
a new environment.
"Copyright Holder(s)" refers to all individuals and companies who have a
copyright ownership of the Font Software.
"Substantially Changed" refers to Modified Versions which can be easily
identified as dissimilar to the Font Software by users of the Font
Software comparing the Original Version with the Modified Version.
To "Propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification and with or without charging
a redistribution fee), making available to the public, and in some
countries other activities as well.
PERMISSION & CONDITIONS
This licence does not grant any rights under trademark law and all such
rights are reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of the Font Software, to propagate the Font Software, subject to
the below conditions:
1) Each copy of the Font Software must contain the above copyright
notice and this licence. These can be included either as stand-alone
text files, human-readable headers or in the appropriate machine-
readable metadata fields within text or binary files as long as those
fields can be easily viewed by the user.
2) The font name complies with the following:
(a) The Original Version must retain its name, unmodified.
(b) Modified Versions which are Substantially Changed must be renamed to
avoid use of the name of the Original Version or similar names entirely.
(c) Modified Versions which are not Substantially Changed must be
renamed to both (i) retain the name of the Original Version and (ii) add
additional naming elements to distinguish the Modified Version from the
Original Version. The name of such Modified Versions must be the name of
the Original Version, with "derivative X" where X represents the name of
the new work, appended to that name.
3) The name(s) of the Copyright Holder(s) and any contributor to the
Font Software shall not be used to promote, endorse or advertise any
Modified Version, except (i) as required by this licence, (ii) to
acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with
their explicit written permission.
4) The Font Software, modified or unmodified, in part or in whole, must
be distributed entirely under this licence, and must not be distributed
under any other licence. The requirement for fonts to remain under this
licence does not affect any document created using the Font Software,
except any version of the Font Software extracted from a document
created using the Font Software may only be distributed under this
licence.
TERMINATION
This licence becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
DEALINGS IN THE FONT SOFTWARE.

BIN
assets/font/Ubuntu-Bold.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
assets/images/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

BIN
bun.lockb Normal file

Binary file not shown.

31
deploy.sh Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env sh
# abort on errors
set -e
# clean up previous
rm -rf dist
# build website
bun run build
# change to build directory
cd dist
# create .nojekyll file
touch .nojekyll
# git init
git init
# git remote (required for .gitconfig)
git remote add origin git@github.com:chora-io/website.git
# git commit
git add -A
git commit -m 'publish'
# push to gh-pages branch
git push origin main:gh-pages -f
cd -

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1782847189,
"narHash": "sha256-twXPFqFsrrY5r28Zh7Homgcp2gUMBgQ6WDS98Q/3xFI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b6018f87da91d19d0ab4cf979885689b469cdd41",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-25.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

26
flake.nix Normal file
View file

@ -0,0 +1,26 @@
{
description = "flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
# shell for `nix develop`
devShells.${system}.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
bun
];
};
# packages for `nix build` and `nix run`
packages.${system} = {
};
};
}

1
module.d.ts vendored Normal file
View file

@ -0,0 +1 @@
declare module '*.module.css'

5
next-env.d.ts vendored Normal file
View file

@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

8
next.config.js Normal file
View file

@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
distDir: 'dist',
output: 'export',
images: { unoptimized: true },
}
module.exports = nextConfig

44
package.json Normal file
View file

@ -0,0 +1,44 @@
{
"name": "website",
"private": true,
"description": "chora website",
"version": "0.0.0",
"homepage": "https://chora.io",
"bugs": {
"url": "https://github.com/chora-io/website/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/chora-io/website"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"lint": "next lint",
"format": "prettier --write .",
"test": "echo 'test not configured'",
"clean": "rm -rf .next dist node_modules"
},
"dependencies": {
"gray-matter": "^4",
"next": "^14",
"react": "^18",
"react-dom": "^18",
"remark": "^15",
"remark-html": "^16"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^6",
"@typescript-eslint/parser": "^6",
"autoprefixer": "^10",
"eslint": "^8",
"eslint-config-next": "^14",
"postcss": "^8",
"prettier": "^3",
"sharp": "^0.33",
"typescript": "^5"
}
}

5
postcss.config.js Normal file
View file

@ -0,0 +1,5 @@
module.exports = {
plugins: {
autoprefixer: {},
},
}

1
public/CNAME Normal file
View file

@ -0,0 +1 @@
chora.io

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

86
styles/banner.css Normal file
View file

@ -0,0 +1,86 @@
/* banner */
.banner {
align-items: center;
display: flex;
font-size: 1.5em;
justify-content: center;
min-height: 10vh;
padding: 2em 0;
text-align: center;
}
@media (max-width: 850px) {
.banner {
font-size: 1em;
}
}
.banner h1 {
font-size: 1.75em;
margin-top: 2.5%;
padding: 0.15em 0;
}
@media (max-width: 850px) {
.banner h1 {
padding: 0.1em 0 !important;
}
}
.banner p {
padding: 0.2em 0;
}
@media (max-width: 850px) {
.banner p {
padding: 0.15em 0 !important;
}
}
.banner p > i {
color: var(--color-theme);
}
/* banner-full */
.banner-full {
composes: banner;
min-height: calc(100vh - var(--header-height));
padding: 0;
}
.banner-full > div {
margin-bottom: calc(1% + var(--header-height));
}
/* banner-document */
.banner-document {
composes: banner;
font-size: 1em;
}
.banner-document h1 {
color: var(--color-theme);
font-size: 1.5em;
margin: 0.5em 0;
}
@media (max-width: 850px) {
.banner-document h1 {
font-size: 1.25em;
}
}
.banner-document h2,
.banner-document h3 {
color: var(--color-text);
font-size: 1em;
font-weight: 300;
opacity: 0.8;
}
.banner-document h3 {
margin-top: 1em;
}

78
styles/content.css Normal file
View file

@ -0,0 +1,78 @@
/* content */
.content {
align-items: center;
background: var(--background-primary);
display: flex;
font-size: 1.2em;
justify-content: center;
}
@media (max-width: 850px) {
.content {
font-size: 1em;
padding: 0 2em;
}
}
.content > div {
display: block;
max-width: 650px;
padding: 2em 0 4em 0;
}
@media (max-width: 850px) {
.content > div {
padding: 1em 0 2em 0;
}
}
.content > div > h1 {
font-size: 1.8em;
padding: 0.5em 0;
}
.content > div > h2 {
padding: 0.25em 0;
}
@media (max-width: 850px) {
.content > div > h2 {
padding-bottom: 0;
}
}
.content > div > p {
padding: 1em 0;
}
.content > div > a {
display: block;
}
.content h2 {
margin: 0.5em 0;
}
.content ul {
list-style-position: inside;
margin: 0.5em 0 2em 0;
}
.content li {
line-height: 1.75;
}
.content hr {
border: 1px solid var(--box-shadow-color);
border-bottom-width: 0;
box-shadow: 0 0 1px var(--box-shadow-color);
margin: 5vh 0;
}
/* content-full */
.content-full {
composes: content;
min-height: calc(100vh - var(--header-height) - var(--footer-height));
}

61
styles/page.css Normal file
View file

@ -0,0 +1,61 @@
/* page */
.page {
margin-top: var(--header-height);
min-height: calc(100vh - var(--header-height) - var(--footer-height));
}
/* page-center */
.page-center {
composes: page;
align-items: center;
display: flex;
justify-content: center;
text-align: center;
}
.page-center > div {
margin-bottom: 10vh;
}
/* page-center-not-found */
.page-center-not-found {
composes: page-center;
background: var(--background-primary);
}
@media (max-width: 850px) {
.page-center-not-found {
padding: 0 1.5em;
}
}
.page-center-not-found h1 {
color: var(--color-theme);
font-size: 3em;
margin-bottom: 0.25em;
}
@media (max-width: 850px) {
.page-center-not-found h1 {
font-size: 2em;
}
}
.page-center-not-found h2 {
font-size: 2em;
font-weight: 300;
margin-bottom: 0.5em;
}
@media (max-width: 850px) {
.page-center-not-found h2 {
font-size: 1.25em;
}
}
.page-center-not-found p {
font-style: italic;
}

34
tsconfig.json Normal file
View file

@ -0,0 +1,34 @@
{
"compilerOptions": {
"baseUrl": "./",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@utils": ["utils/index.ts"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"dist/types/**/*.ts"
],
"exclude": ["node_modules"]
}

27
utils/getArtifact.ts Normal file
View file

@ -0,0 +1,27 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { remark } from 'remark'
import html from 'remark-html'
const root = path.join(process.cwd(), 'artifacts')
export async function getArtifact(dir: string, id: string) {
const fullPath = path.join(root, dir, `${id}.md`)
// read file contents
const fileContents = fs.readFileSync(fullPath, 'utf8')
// parse file contents
const { content, data } = matter(fileContents)
// convert markdown to html
const processedContent = await remark().use(html).process(content)
// return id, content, and data
return {
id,
content: processedContent.toString(),
...data,
} as any
}

31
utils/getArtifacts.ts Normal file
View file

@ -0,0 +1,31 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
const root = path.join(process.cwd(), 'artifacts')
export const getArtifacts = (dir: string) => {
const fileNames = fs.readdirSync(root + '/' + dir)
const filtered = fileNames.filter((fileName) => fileName.includes(`.md`))
return filtered.map((fileName) => {
// set id
const id = fileName.replace(/\.md$/, '')
// set full path
const fullPath = path.join(root, dir, fileName)
// read file contents
const fileContents = fs.readFileSync(fullPath, 'utf8')
// parse file contents
const { data } = matter(fileContents)
// return id and data
return {
id,
...data,
}
}) as any[]
}

2
utils/index.ts Normal file
View file

@ -0,0 +1,2 @@
export { getArtifact } from './getArtifact'
export { getArtifacts } from './getArtifacts'