Skip to content

Commit 8122f87

Browse files
committed
Introducing enhance.dev
0 parents  commit 8122f87

File tree

141 files changed

+21507
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+21507
-0
lines changed

.github/workflows/build.yml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Node CI
2+
3+
# Push tests pushes; PR tests merges
4+
on: [push, pull_request]
5+
6+
defaults:
7+
run:
8+
shell: bash
9+
10+
jobs:
11+
# Test the build
12+
build:
13+
# Setup
14+
runs-on: ubuntu-latest
15+
16+
# Go
17+
steps:
18+
- name: Check out repo
19+
uses: actions/checkout@v3
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 16
25+
26+
- name: Env
27+
run: |
28+
echo "Event name: ${{ github.event_name }}"
29+
echo "Git ref: ${{ github.ref }}"
30+
echo "GH actor: ${{ github.actor }}"
31+
echo "SHA: ${{ github.sha }}"
32+
VER=`node --version`; echo "Node ver: $VER"
33+
VER=`npm --version`; echo "npm ver: $VER"
34+
35+
- name: Install
36+
run: npm install
37+
38+
- name: Test
39+
run: npm test
40+
env:
41+
CI: true
42+
43+
- name: Notify
44+
uses: homoluctus/slatify@master
45+
if: github.ref == 'refs/heads/main' && failure()
46+
with:
47+
type: ${{ job.status }}
48+
job_name: "*Build*"
49+
url: ${{ secrets.SLACK_NOTIFY }}
50+
commit: true
51+
token: ${{ secrets.GITHUB_TOKEN }}
52+
53+
# Assuming all that went fine (and it's main): deploy!
54+
deploy:
55+
# Setup
56+
needs: build
57+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
58+
runs-on: ubuntu-latest
59+
60+
# Go
61+
steps:
62+
- name: Check out repo
63+
uses: actions/checkout@v3
64+
65+
- name: Set up Node.js
66+
uses: actions/setup-node@v3
67+
with:
68+
node-version: 16
69+
70+
- name: Install
71+
run: npm i
72+
73+
- name: Staging Deploy
74+
if: github.ref == 'refs/heads/main' && github.repository == 'enhance-dev/enhance.dev'
75+
run: npx arc deploy --staging
76+
env:
77+
CI: true
78+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
79+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
80+
81+
- name: Production Deploy
82+
if: startsWith(github.ref, 'refs/tags/v') && github.repository == 'enhance-dev/enhance.dev'
83+
84+
run: npx arc deploy --production
85+
env:
86+
CI: true
87+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
88+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
89+
90+
- name: Notify
91+
uses: homoluctus/slatify@master
92+
if: always()
93+
with:
94+
type: ${{ job.status }}
95+
job_name: "*Publish*"
96+
url: ${{ secrets.SLACK_NOTIFY }}
97+
commit: true
98+
token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node_modules
2+
3+
.arc-env
4+
.env
5+
preferences.arc
6+
prefs.arc
7+
sam.json
8+
sam.yaml
9+
10+
static.json
11+
public/css/styles.css
12+
public/bundles
13+
14+
.DS_Store
15+
.vscode
16+
*-lock.yaml

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Enhance.dev Website
2+
3+
Powered by HTML ([Enhance](https://enhance.dev)), cloud functions ([Architect](https://arc.codes)), and Markdown ([Arcdown](https://github.coms/architect/arcdown)).
4+
5+
## Writing docs
6+
7+
All documentation content lives in `src/views/docs/md`.
8+
9+
Navigation data is stored in `src/views/docs/nav-data.mjs`.
10+
11+
## Development
12+
13+
Recommended prefs.arc:
14+
15+
```arc
16+
@sandbox
17+
livereload true
18+
```
19+
20+
### Main site
21+
22+
Currently redirects to Enhance documentation at "/docs/".
23+
24+
### Docs engine
25+
26+
The main "/docs/*" HTTP function is `src/http/get-docs-catchall/index.mjs`.
27+
(`src/http/get-docs/` redirects "/docs" to "/docs/")
28+
29+
This function uses the path (accounting for trailing slashes) to look up a .md document and render it to HTML with Arcdown. This HTML is combined with `nav-data` and then handed to `enhance-ssr` to render the full view.
30+
31+
### Tutorial
32+
33+
WIP `src/http/get-tutorial-catchall/`
34+
35+
### Playground
36+
37+
WIP `src/http/get-playground/`

app.arc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@app
2+
enhance-dev-new
3+
4+
@static
5+
fingerprint true
6+
7+
@plugins
8+
enhance/arc-plugin-enhance
9+
10+
@enhance-styles
11+
filename css/styles.css
12+
config css-config.json
13+
14+
@bundles
15+
mux-player 'node_modules/@mux/mux-player'
16+
17+
@aws
18+
runtime nodejs16.x
19+
architecture arm64
20+
region us-west-2
21+
profile smallwins

app/api/discord.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export async function get() {
2+
return {
3+
statusCode: 302,
4+
location: 'https://discord.gg/J8bUSfKs8W',
5+
}
6+
}

app/api/docs.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export async function get() {
2+
return {
3+
statusCode: 301,
4+
location: '/docs/',
5+
}
6+
}

app/api/docs/$$.mjs

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* eslint-disable filenames/match-regex */
2+
import { readFileSync } from 'fs'
3+
import { URL } from 'url'
4+
import { Arcdown } from 'arcdown'
5+
import arcStaticImg from 'markdown-it-arc-static-img'
6+
import navDataLoader, {
7+
unslug,
8+
other as otherLinks,
9+
} from '../../docs/nav-data.mjs'
10+
import HljsLineWrapper from '../../docs/hljs-line-wrapper.mjs'
11+
12+
const arcdown = new Arcdown({
13+
pluginOverrides: {
14+
markdownItToc: {
15+
containerClass: 'toc mb2 ml-2',
16+
listType: 'ul',
17+
},
18+
},
19+
plugins: [arcStaticImg],
20+
hljs: {
21+
sublanguages: { javascript: ['xml', 'css'] },
22+
plugins: [new HljsLineWrapper({ className: 'code-line' })],
23+
},
24+
})
25+
26+
/** @type {import('@enhance/types').EnhanceApiFn} */
27+
export async function get(request) {
28+
const { path: activePath } = request
29+
let docPath = activePath.replace(/^\/?docs\//, '') || 'index'
30+
if (docPath.endsWith('/')) {
31+
docPath += 'index' // trailing slash == index.md file
32+
}
33+
34+
const gacode =
35+
process.env.ARC_ENV === 'production' ? 'G-FQHNPN78V3' : 'G-0ES194BJQ6'
36+
37+
const docURL = new URL(`../../docs/md/${docPath}.md`, import.meta.url)
38+
39+
const sidebarData = navDataLoader('docs', activePath)
40+
41+
let docMarkdown
42+
try {
43+
docMarkdown = readFileSync(docURL.pathname, 'utf-8')
44+
} catch (_err) {
45+
let searchTerm = null
46+
if (!docPath.endsWith('/index')) {
47+
const docPathParts = docPath.split('/')
48+
searchTerm = docPathParts.pop()
49+
searchTerm = unslug(searchTerm)
50+
}
51+
const initialState = {
52+
doc: {
53+
title: '404',
54+
path: docPath,
55+
term: searchTerm || '',
56+
},
57+
otherLinks,
58+
sidebarData,
59+
searchTerm,
60+
gacode,
61+
}
62+
63+
return { statusCode: 404, json: initialState }
64+
}
65+
const doc = await arcdown.render(docMarkdown)
66+
67+
let gitHubLink = 'https://github.com/enhance-dev/enhance.dev/edit/main/src/'
68+
gitHubLink += `views/docs/md/${docPath}.md`
69+
70+
const initialState = {
71+
doc,
72+
gitHubLink,
73+
otherLinks,
74+
sidebarData,
75+
gacode,
76+
}
77+
78+
let cacheControl =
79+
process.env.ARC_ENV === 'production'
80+
? 'max-age=3600;'
81+
: 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0'
82+
83+
return {
84+
cacheControl,
85+
json: initialState,
86+
}
87+
}

app/api/email/interest/add.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import data from '@begin/data'
2+
3+
/** @type {import('@enhance/types').EnhanceApiFn} */
4+
export async function post(req) {
5+
const email = req.body.email
6+
const timestamp = new Date(Date.now()).toISOString()
7+
await data.set({ table: 'email', email, timestamp })
8+
return {
9+
statusCode: 303,
10+
location: '/email/thank',
11+
}
12+
}

app/api/index.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export async function get() {
2+
return {
3+
statusCode: 302,
4+
location: '/docs/',
5+
}
6+
}

app/docs/hljs-line-wrapper.mjs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* eslint-disable fp/no-class */
2+
3+
export default class {
4+
constructor(options) {
5+
this.className = options.className
6+
}
7+
8+
'after:highlight'(result) {
9+
const tokens = []
10+
11+
const safelyTagged = result.value.replace(
12+
/(<span [^>]+>)|(<\/span>)|(\n)/g,
13+
(match) => {
14+
if (match === '\n') {
15+
return `${'</span>'.repeat(tokens.length)}\n${tokens.join('')}`
16+
}
17+
18+
if (match === '</span>') {
19+
tokens.pop()
20+
} else {
21+
tokens.push(match)
22+
}
23+
24+
return match
25+
}
26+
)
27+
28+
result.value = safelyTagged
29+
.split('\n')
30+
.reduce((result, line, index, lines) => {
31+
const lastLine = index + 1 === lines.length
32+
if (!(lastLine && line.length === 0)) {
33+
result.push(
34+
`<span class="${this.className || 'hljs-line'}">${line}</span>`
35+
)
36+
}
37+
return result
38+
}, [])
39+
.join('\n')
40+
}
41+
}

0 commit comments

Comments
 (0)