- {#if docs_data}
+ {#if url === "/docs/"}
+
+ {#if readme_docs}
+ {@html readme_docs}
+ {/if}
+
+ {:else if docs_data}
{#each docs_data.exports as exp}
jump(exp.slug) }>{ exp.name }
@@ -202,11 +238,10 @@
{/each}
- { url }
- {#if docs_data.comment}
- {@html docs_data.comment}
- {/if}
-
+ { url }
+ {#if docs_data.comment}
+ {@html docs_data.comment}
+ {/if}
{#each docs_data.exports as exp}
diff --git a/client/api.js b/client/api.js
index e0c002c..2746782 100644
--- a/client/api.js
+++ b/client/api.js
@@ -330,6 +330,29 @@ export const raw = async (url, method, body, unauthed_action) => {
}
}
+/*
+ Used for fetching basic resources, not JSON data from the API. Uses the
+ same return signature as `raw()` but doesn't attempt a JSON conversion,
+ and only does a "GET" request. It returns the result of `res.blob()`
+ so you can convert it to a string or JSON as you need, or leave it if
+ it's a binary file.
+
+ + `url string` -- URL to get.
+ + ___return___ `Array[status, Blob|{}]` -- Returns a Blob or when status is 500 a `{"message": "Error message"}`.
+ */
+export const blob = async (url) => {
+ let data;
+
+ try {
+ let res = await fetch(url, fetch_opts);
+ data = await res.blob();
+ return [res.status, data];
+ } catch(error) {
+ log.error(error, "Failed to parse reply body as JSON. Text is:", data, "error", error, "URL", url);
+ return [500, {"message": "Exception processing request. See log.debug."}];
+ }
+}
+
/*
The GET method request. To keep things consistent with the
other requests this accepts a `data` parameter, but it URL
@@ -439,5 +462,5 @@ export const schema = async (table) => {
export default {
post, get, put, del, mock, options, fetch_opts,
- logout_user, validate, can_submit, clean_form, schema
+ logout_user, validate, can_submit, clean_form, schema, blob
}
diff --git a/commands/codedoc.js b/commands/codedoc.js
index 2754026..0b9601b 100644
--- a/commands/codedoc.js
+++ b/commands/codedoc.js
@@ -15,7 +15,8 @@ export const description = "Describe your command here."
// your command uses the npm package commander's options format
export const options = [
- ["--quiet", "Don't output the stats at the end."]
+ ["--quiet", "Don't output the stats at the end."],
+ ["--readme", "README file to use as the initial page", "README.md"]
]
// example of a positional argument, it's the 1st argument to main
@@ -329,6 +330,10 @@ export const main = async (source_globs, opts) => {
const index_name = path.join(opts.output, "index.json");
fs.writeFileSync(index_name, dump(index));
+ // render the README.md to the initial docs
+ const readme_name = path.join(opts.output, "index.html");
+ const md_out = RENDERER.render(fs.readFileSync(opts.readme).toString());
+ fs.writeFileSync(readme_name, md_out);
const percent = Math.floor(100 * STATS.docs / STATS.total);
diff --git a/lib/builderator.js b/lib/builderator.js
index 7b6bcff..edffb92 100644
--- a/lib/builderator.js
+++ b/lib/builderator.js
@@ -11,7 +11,7 @@ import Path from "path";
import { execSync } from "child_process";
/*
- Fixes some common problems with `fast-glob` on windows. I removes
+ Fixes some common problems with `fast-glob` on windows. It removes
leading "C:\" from paths and replaces all of the `\\` with `/`.
__BUG__: This obviously won't work if you're on a different drive than C:.