Skip to content

Commit

Permalink
Adopt typedoc for API docs (#66), closes #63
Browse files Browse the repository at this point in the history
* Build the API docs when the site is being built

* Add watch:docs command

* Add a custom CSS stub file

* Use a custom index page for the API docs

* Add support for the abstract tag

* Hide the protected and external filters since we don't have such modifiers

* Update inline docs so that Typedoc parses them correctly

* Add (partial) support for Prism

In Typedoc, we can use no extensibility point [1] to replace the built-in syntax highlighter (Shiki) with Prism. The only way to do that is to write a custom theme that (somehow) uses another syntax highlighter or doesn't highlight code blocks at all. I tried but failed — there's a ton of stuff to know to be able to do that (at least from my perspective).

However, we can make the built-in markdown plugin (Marked) use a custom highlight function instead of the one that calls the Typedoc built-in syntax highlighter. That means that our markdown files and code blocks in the code comments (Typedoc supports markdown in comments) can be highlighted by Prism.

[1] https://discord.com/channels/508357248330760243/829307039447515176/1202594912051273848
  • Loading branch information
DmitrySharabin authored Feb 2, 2024
1 parent 1ac1489 commit 1aed450
Show file tree
Hide file tree
Showing 41 changed files with 1,295 additions and 820 deletions.
3 changes: 2 additions & 1 deletion .eleventyignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/contributing.md
**/contributing.md
API.md
1 change: 1 addition & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Index page for the API documentation
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<header class="home no-home-link">

<img src="logo.svg" width="100" alt="Logo showing a cloud presented as a tree" />
<img src="/logo.svg" width="100" alt="Logo showing a cloud presented as a tree" />

<h1 class="logo"><span class="ma">ma</span>data</h1>

Expand Down
3 changes: 3 additions & 0 deletions api.postcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
Custom CSS for the API docs goes here...
*/
11 changes: 6 additions & 5 deletions backends/basic/element.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* Save in an HTML element
* @class Element
*/

import Backend from "../../src/backend.js";
import {$} from "../../src/util.js";

/**
* Read and write data into an HTML element.
* @class Element
* @extends Backend
* @category Basic
*/
export default class Element extends Backend {
constructor (url, o) {
super(url, o);
Expand Down
10 changes: 6 additions & 4 deletions backends/basic/local.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/**
* Store data in localStorage
* @class Local
*/
import Backend from "../../src/backend.js";
import { localStorage } from "../../src/node-shims.js";

/**
* Store data in the browser's localStorage.
* @class Local
* @extends Backend
* @category Basic
*/
export default class Local extends Backend {
constructor (url, o) {
super(url, o);
Expand Down
8 changes: 5 additions & 3 deletions backends/basic/remote.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Backend from "../../src/backend.js";

/**
* Load the URL as a remote resource. No save.
* @class Remote
* Load from a remote URL, no save
* @extends Backend
* @category Basic
*/
import Backend from "../../src/backend.js";

export default class Remote extends Backend {
constructor (url, o) {
super(url, o);
Expand Down
5 changes: 5 additions & 0 deletions backends/coda/api/coda-api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Coda from "../coda.js";

/**
* @class CodaAPI
* @extends Coda
* @category Coda
*/
export default class CodaAPI extends Coda {
async get (ref = this.ref) {
return this.request(ref.url);
Expand Down
5 changes: 3 additions & 2 deletions backends/coda/coda.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import OAuthBackend from "../../src/oauth-backend.js";

/**
* @class Coda
* @extends OAuthBackend
* @category Coda
*/
import OAuthBackend from "../../src/oauth-backend.js";

export default class Coda extends OAuthBackend {
constructor (url, o) {
super(url, o);
Expand Down
5 changes: 5 additions & 0 deletions backends/coda/table/coda-table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Coda from "../coda.js";

/**
* @class CodaTable
* @extends Coda
* @category Coda
*/
export default class CodaTable extends Coda {
async get (ref = this.ref) {
if (!ref.tableId) {
Expand Down
5 changes: 3 additions & 2 deletions backends/dropbox/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import OAuthBackend from "../../src/oauth-backend.js";

/**
* Dropbox backend.
* @class Dropbox
* @extends OAuthBackend
*/
import OAuthBackend from "../../src/oauth-backend.js";

export default class Dropbox extends OAuthBackend {
static apiDomain = "https://api.dropboxapi.com/2/";
static oAuth = "https://www.dropbox.com/oauth2/authorize";
Expand Down
10 changes: 5 additions & 5 deletions backends/firebase/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Firebase backend.
* @class Firebase
* @extends OAuthBackend
*/
import AuthBackend from "../../src/auth-backend.js";
import { readFile, toArray } from "../../src/util.js";

Expand All @@ -11,6 +6,11 @@ import { getAuth, onAuthStateChanged, signInWithPopup, signOut, GoogleAuthProvid
import { getFirestore, doc, collection, getDoc, getDocs, setDoc, addDoc, deleteDoc } from "https://www.gstatic.com/firebasejs/10.5.0/firebase-firestore-lite.js";
import { getStorage, ref, uploadString, getDownloadURL, deleteObject } from "https://www.gstatic.com/firebasejs/10.5.0/firebase-storage.js";

/**
* Firebase backend.
* @class Firebase
* @extends OAuthBackend
*/
export default class Firebase extends AuthBackend {
constructor (url, o) {
super(url, o);
Expand Down
6 changes: 6 additions & 0 deletions backends/github/api/github-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Github from "../github.js";
// import hooks from "../../../src/hooks.js";

/**
* Backend for performing raw API calls with the REST or GraphQL API to GitHub repositories.
* @class GithubAPI
* @extends Github
* @category GitHub
*/
export default class GithubAPI extends Github {
update (url, o) {
super.update(url, o);
Expand Down
10 changes: 6 additions & 4 deletions backends/github/file/github-file.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/**
* @class GithubFile
* @extends Github
*/
import Github from "../github.js";
import hooks from "../../../src/hooks.js";
import {readFile, delay} from "../../../src/util.js";

/**
* Backend for reading and writing data and uploading files in GitHub repositories.
* @class GithubFile
* @extends Github
* @category GitHub
*/
export default class GithubFile extends Github {
static fileBased = true;

Expand Down
9 changes: 5 additions & 4 deletions backends/github/gist/github-gist.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Github from "../github.js";
import hooks from "../../../src/hooks.js";

/**
* Github Gist backend
* Github Gist backend.
* @class GithubGist
* @extends Github
* @category GitHub
*/
import Github from "../github.js";
import hooks from "../../../src/hooks.js";

export default class GithubGist extends Github {
async get (file = this.ref) {
if (this.isAuthenticated()) {
Expand Down
6 changes: 4 additions & 2 deletions backends/github/github.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import OAuthBackend from "../../src/oauth-backend.js";

/**
* Base class for all Github backends, containing auth methods.
* @class Github
* @extends OAuthBackend
* @category GitHub
*/
import OAuthBackend from "../../src/oauth-backend.js";

export default class Github extends OAuthBackend {
constructor (url, o) {
super(url, o);
Expand Down
5 changes: 3 additions & 2 deletions backends/google/calendar/google-calendar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Google from "../google.js";

/**
* Google Calendar backend. Read-only for now.
* @class GoogleCalendar
* @extends Google
* @category Google
*/
import Google from "../google.js";

export default class GoogleCalendar extends Google {
async get (ref = this.ref) {
let call = `${ref.calendarId}/events?key=${this.apiKey}`;
Expand Down
6 changes: 4 additions & 2 deletions backends/google/drive/google-drive.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Google from "../google.js";

/**
* Google Drive backend.
* @class GoogleDrive
* @extends Google
* @category Google
*/
import Google from "../google.js";

export default class GoogleDrive extends Google {
static apiDomain = "https://www.googleapis.com/";
static scopes = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"];
Expand Down
7 changes: 4 additions & 3 deletions backends/google/google.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import OAuthBackend from "../../src/oauth-backend.js";

/**
* Base class for all Google backends, containing auth methods
* Base class for all Google backends, containing auth methods.
* @class Google
* @extends OAuthBackend
* @category Google
*/
import OAuthBackend from "../../src/oauth-backend.js";

export default class Google extends OAuthBackend {
constructor (url, o) {
super(url, o);
Expand Down
5 changes: 3 additions & 2 deletions backends/google/sheets/google-sheets.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Google from "../google.js";

/**
* Google Sheets backend.
* @class GoogleSheets
* @extends Google
* @category Google
*/
import Google from "../google.js";

export default class GoogleSheets extends Google {
/**
* Read data from the spreadsheet.
Expand Down
2 changes: 1 addition & 1 deletion backends/index-fn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Export all backends without side effects.
* @module index-fn
* Export all backends without side effects
*/

export * from "./basic/index.js";
Expand Down
4 changes: 2 additions & 2 deletions backends/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @module index
* Export all backends and register them
* Export all backends and register them.
* @module Backends
*/
import Backend from "../src/backend.js";
import * as backends from "./index-fn.js";
Expand Down
4 changes: 4 additions & 0 deletions formats/csv/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Format from "../../src/format.js";
import { parse, stringify } from "../../lib/csv/dist/esm/sync.js";

/**
* @class CSV
* @extends Format
*/
export default class CSV extends Format {
static defaultOptions = {
parse: {
Expand Down
2 changes: 1 addition & 1 deletion formats/index-fn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Export all formats without side effects.
* @module formats/index-fn
* Export all formats without side effects
*/

export {default as JSON} from "./json/index.js";
Expand Down
4 changes: 2 additions & 2 deletions formats/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @module formats/index
* Export all formats and register them
* Export all formats and register them.
* @module Formats
*/
import Format from "../src/format.js";
import * as formats from "./index-fn.js";
Expand Down
4 changes: 4 additions & 0 deletions formats/json/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Format from "../../src/format.js";

/**
* @class JSON
* @extends Format
*/
export default class JSON extends Format {
static defaultOptions = {
stringify: {
Expand Down
4 changes: 4 additions & 0 deletions formats/text/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Format from "../../src/format.js";

/**
* @class Text
* @extends Format
*/
export default class Text extends Format {
static extensions = ["txt", "md"];
static mimeTypes = ["text/plain"];
Expand Down
4 changes: 4 additions & 0 deletions formats/yaml/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Format from "../../src/format.js";
import { parse, stringify } from "../../lib/yaml/browser/index.js";

/**
* @class YAML
* @extends Format
*/
export default class YAML extends Format {
static extensions = ["yaml", "yml"];
static mimeTypes = ["application/yaml", "application/x-yaml", "text/yaml"];
Expand Down
Loading

0 comments on commit 1aed450

Please sign in to comment.