Skip to content

Commit 07208b6

Browse files
committed
Initial commit.
1 parent 7832538 commit 07208b6

File tree

7 files changed

+175
-130
lines changed

7 files changed

+175
-130
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
indent_style = space
12+
indent_size = 2

.eslintrc.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
// this is required for dynamic import() and top-level await
5+
ecmaVersion: 2022,
6+
sourceType: 'module'
7+
},
8+
env: {
9+
node: true
10+
},
11+
extends: [
12+
'digitalbazaar'
13+
],
14+
ignorePatterns: ['node_modules/']
15+
};

.gitignore

Lines changed: 2 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,3 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
.pnpm-debug.log*
9-
10-
# Diagnostic reports (https://nodejs.org/api/report.html)
11-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12-
13-
# Runtime data
14-
pids
15-
*.pid
16-
*.seed
17-
*.pid.lock
18-
19-
# Directory for instrumented libs generated by jscoverage/JSCover
20-
lib-cov
21-
22-
# Coverage directory used by tools like istanbul
23-
coverage
24-
*.lcov
25-
26-
# nyc test coverage
27-
.nyc_output
28-
29-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30-
.grunt
31-
32-
# Bower dependency directory (https://bower.io/)
33-
bower_components
34-
35-
# node-waf configuration
36-
.lock-wscript
37-
38-
# Compiled binary addons (https://nodejs.org/api/addons.html)
39-
build/Release
40-
41-
# Dependency directories
42-
node_modules/
43-
jspm_packages/
44-
45-
# Snowpack dependency directory (https://snowpack.dev/)
46-
web_modules/
47-
48-
# TypeScript cache
49-
*.tsbuildinfo
50-
51-
# Optional npm cache directory
52-
.npm
53-
54-
# Optional eslint cache
55-
.eslintcache
56-
57-
# Optional stylelint cache
58-
.stylelintcache
59-
60-
# Microbundle cache
61-
.rpt2_cache/
62-
.rts2_cache_cjs/
63-
.rts2_cache_es/
64-
.rts2_cache_umd/
65-
66-
# Optional REPL history
67-
.node_repl_history
68-
69-
# Output of 'npm pack'
70-
*.tgz
71-
72-
# Yarn Integrity file
73-
.yarn-integrity
74-
75-
# dotenv environment variable files
76-
.env
77-
.env.development.local
78-
.env.test.local
79-
.env.production.local
80-
.env.local
81-
82-
# parcel-bundler cache (https://parceljs.org/)
83-
.cache
84-
.parcel-cache
85-
86-
# Next.js build output
87-
.next
88-
out
89-
90-
# Nuxt.js build / generate output
91-
.nuxt
92-
dist
93-
94-
# Gatsby files
951
.cache/
96-
# Comment in the public line in if your project uses Gatsby and not Next.js
97-
# https://nextjs.org/blog/next-9-1#public-directory-support
98-
# public
99-
100-
# vuepress build output
101-
.vuepress/dist
102-
103-
# vuepress v2.x temp and cache directory
104-
.temp
105-
.cache
106-
107-
# Docusaurus cache and generated files
108-
.docusaurus
109-
110-
# Serverless directories
111-
.serverless/
112-
113-
# FuseBox cache
114-
.fusebox/
115-
116-
# DynamoDB Local files
117-
.dynamodb/
118-
119-
# TernJS port file
120-
.tern-port
121-
122-
# Stores VSCode versions used for testing VSCode extensions
123-
.vscode-test
124-
125-
# yarn v2
126-
.yarn/cache
127-
.yarn/unplugged
128-
.yarn/build-state.yml
129-
.yarn/install-state.gz
130-
.pnp.*
2+
node_modules/
3+
package-lock.json

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
# w3c-api-browser
1+
# w3c-api-browser
2+
3+
Browse the [W3C API](https://api.w3.org/doc) in your browser!
4+
5+
## Usage
6+
7+
```sh
8+
$ npm i
9+
$ npm run server
10+
$ # Listening on http://localhost:8080
11+
```
12+
13+
## License
14+
15+
[BSD-3-Clause](LICENSE) Copyright 2024 Digital Bazaar, Inc.

byEditor.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import EleventyFetch from '@11ty/eleventy-fetch';
2+
3+
const apiBaseUrl = 'https://api.w3.org';
4+
5+
// TODO: support more editors via configuration or commandline argument
6+
// Manu Sporny's W3C ID
7+
const editorId = 'hhvask30a7co0gs0gcsgosgkowws0k4';
8+
9+
const specs = await EleventyFetch(
10+
// eslint-disable-next-line max-len
11+
`${apiBaseUrl}/users/${editorId}/specifications?embed=true`,
12+
{
13+
duration: '1d',
14+
type: 'json'
15+
});
16+
const {specifications} = specs._embedded;
17+
18+
let csv = `"${['Title', 'First Date', 'Latest Date', 'Latest Status',
19+
'Series Version', 'Short Link', 'Editors'].join('","')}"\n`;
20+
const rows = await Promise.all(specifications.map(async spec => {
21+
// gather editor info
22+
const rv = await EleventyFetch(
23+
`${spec._links['latest-version'].href}/editors?embed=true`,
24+
{
25+
duration: '1d',
26+
type: 'json'
27+
});
28+
const editors = rv?._embedded?.editors || [];
29+
const row = [];
30+
row.push(
31+
spec.title,
32+
spec._links['first-version'].href.split('/').at(-1)
33+
.replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, '$1-$2-$3'),
34+
spec._links['latest-version'].href.split('/').at(-1)
35+
.replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, '$1-$2-$3'),
36+
spec._links['latest-version'].title,
37+
spec['series-version'],
38+
spec.shortlink,
39+
editors.map(editor => editor.name).join(', ')
40+
);
41+
return `"${row.join('","')}"`;
42+
}));
43+
csv += rows.join('\n');
44+
console.log(csv);

index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {Application} from '@curveball/core';
2+
import browser from '@curveball/browser';
3+
4+
// MUST not end in a trailing slash and will be stripped in response bodies for
5+
// to facilitate local browsing.
6+
const apiBaseUrl = 'https://api.w3.org';
7+
const title = 'W3C API';
8+
9+
// port for this browser app to listen on
10+
const port = 8080;
11+
12+
const app = new Application();
13+
app.use(browser({title}));
14+
app.use(async ctx => {
15+
console.dir(ctx.request.requestTarget);
16+
if(ctx.request.requestTarget === '/') {
17+
// adding a home page response with some navigation
18+
ctx.response.body = {
19+
_links: {
20+
groups: {
21+
href: '/groups',
22+
title: 'List Groups'
23+
},
24+
specifications: {
25+
href: '/specifications',
26+
title: 'List Specifications'
27+
},
28+
'code-repository': {
29+
href: 'https://github.com/digitalbazaar/w3c-api-browser'
30+
},
31+
alternate: [
32+
{
33+
href: 'https://api.w3.org/doc',
34+
type: 'text/html',
35+
title: 'W3C API Docs'
36+
},
37+
{
38+
href: 'https://api.w3.org/doc.json',
39+
type: 'application/json',
40+
title: 'W3C API Swagger'
41+
}
42+
]
43+
}
44+
};
45+
} else {
46+
const resp = await fetch(
47+
`${apiBaseUrl}${ctx.request.requestTarget}?embed=true`, {
48+
headers: {
49+
Accept: 'application/json'
50+
}
51+
}
52+
);
53+
const rv = await resp.json();
54+
const localhosted = JSON.stringify(rv).replaceAll(apiBaseUrl, '');
55+
ctx.response.body = localhosted;
56+
ctx.response.type = 'application/hal+json';
57+
}
58+
});
59+
app.listen(port);
60+
console.log(`Listening on http://localhost:${port}`);

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "w3c-api-browser",
3+
"version": "0.0.0",
4+
"description": "Browse the W3C API (HAL) output.",
5+
"type": "module",
6+
"main": "index.js",
7+
"scripts": {
8+
"serve": "node index.js",
9+
"test": "echo \"Error: no test specified\" && exit 1",
10+
"lint": "eslint \"**/*.{js,cjs}\""
11+
},
12+
"keywords": [
13+
"w3c",
14+
"api",
15+
"hal"
16+
],
17+
"author": "Digital Bazaar, Inc.",
18+
"license": "BSD-3-Clause",
19+
"dependencies": {
20+
"@11ty/eleventy-fetch": "^4.0.1",
21+
"@curveball/browser": "^1.1.1",
22+
"@curveball/core": "^1.0.0",
23+
"@curveball/validator": "^1.0.0",
24+
"eslint": "^8.45.0",
25+
"eslint-config-digitalbazaar": "^5.0.1"
26+
}
27+
}

0 commit comments

Comments
 (0)