Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
25 changes: 25 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint

permissions:
contents: read

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
node-version: [24.x]
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run eslint
run: npm run lint
132 changes: 3 additions & 129 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,130 +1,4 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
node_modules/
*.sw[nop]
*~
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# w3c-api-browser Changelog

## 0.1.0

* Initial release.
11 changes: 11 additions & 0 deletions LICENSES/BSD-3-Clause.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) <year> <owner>.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# w3c-api-browser
# w3c-api-browser

Browse the [W3C API](https://api.w3.org/doc) in your browser!

## Usage

```sh
$ npm i
$ npm start
Listening on http://localhost:8080
```

## License

[BSD-3-Clause](LICENSE) Copyright 2024 Digital Bazaar, Inc.
8 changes: 8 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version = 1
SPDX-PackageSupplier = "Digital Bazaar, Inc. <support@digitalbazaar.com>"

[[annotations]]
path = ["**.md", ".editorconfig", ".github/**", ".gitignore", "eslint.config.js", "package.json", "package-lock.json"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2012-2024 Digital Bazaar, Inc."
SPDX-License-Identifier = "BSD-3-Clause"
48 changes: 48 additions & 0 deletions byEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*!
* Copyright 2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
import EleventyFetch from '@11ty/eleventy-fetch';

const apiBaseUrl = 'https://api.w3.org';

// TODO: support more editors via configuration or commandline argument
// Manu Sporny's W3C ID
const editorId = 'hhvask30a7co0gs0gcsgosgkowws0k4';

const specs = await EleventyFetch(
`${apiBaseUrl}/users/${editorId}/specifications?embed=true`,
{
duration: '1d',
type: 'json'
});
const {specifications} = specs._embedded;

let csv = `"${['Title', 'First Date', 'Latest Date', 'Latest Status',
'Series Version', 'Short Link', 'Editors'].join('","')}"\n`;
const rows = await Promise.all(specifications.map(async spec => {
// gather editor info
const rv = await EleventyFetch(
`${spec._links['latest-version'].href}/editors?embed=true`,
{
duration: '1d',
type: 'json'
});
const editors = rv?._embedded?.editors || [];
const row = [];
row.push(
spec.title,
spec._links['first-version'].href.split('/').at(-1)
.replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, '$1-$2-$3'),
spec._links['latest-version'].href.split('/').at(-1)
.replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, '$1-$2-$3'),
spec._links['latest-version'].title,
spec['series-version'],
spec.shortlink,
editors.map(editor => editor.name).join(', ')
);
return `"${row.join('","')}"`;
}));
csv += rows.join('\n');
console.log(csv);
5 changes: 5 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import config from '@digitalbazaar/eslint-config/node-recommended';

export default [
...config
];
68 changes: 68 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*!
* Copyright 2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
import {Application} from '@curveball/core';
import browser from '@curveball/browser';

// MUST not end in a trailing slash and will be stripped in response bodies for
// to facilitate local browsing.
const apiBaseUrl = 'https://api.w3.org';
const title = 'W3C API';

// port for this browser app to listen on
const port = 8080;

const app = new Application();
app.use(browser({title, navigationLinks: {
previous: {priority: -1}, next: {priority: 1}}}));
app.use(async ctx => {
console.dir(ctx.request.requestTarget);
if(ctx.request.requestTarget === '/') {
// adding a home page response with some navigation
ctx.response.body = {
_links: {
groups: {
href: '/groups',
title: 'List Groups'
},
specifications: {
href: '/specifications',
title: 'List Specifications'
},
'code-repository': {
href: 'https://github.com/digitalbazaar/w3c-api-browser'
},
alternate: [
{
href: 'https://api.w3.org/doc',
type: 'text/html',
title: 'W3C API Docs'
},
{
href: 'https://api.w3.org/doc.json',
type: 'application/json',
title: 'W3C API Swagger'
}
]
}
};
} else {
const newUrl = new URL(`${apiBaseUrl}${ctx.request.requestTarget}`);
if(!newUrl.searchParams.has('embed')) {
newUrl.searchParams.append('embed', 'true');
}
const resp = await fetch(newUrl, {
headers: {
Accept: 'application/json'
}
});
const rv = await resp.json();
const localhosted = JSON.stringify(rv).replaceAll(apiBaseUrl, '');
ctx.response.body = localhosted;
ctx.response.type = 'application/hal+json';
}
});
app.listen(port);
console.log(`Listening on http://localhost:${port}`);
Loading