Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
erayd committed Nov 22, 2020
1 parent 93f3621 commit 0338283
Showing 13 changed files with 12,663 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
12,586 changes: 12,586 additions & 0 deletions public/dist/slightly-1.1.0.dist.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/dist/slightly-1.1.0.dist.js.sri
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256-ESoAgVJl33qrPqIzALgkztic05pw+eWw+HP7RjVat3M=
1 change: 1 addition & 0 deletions public/dist/slightly-1.1.0.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/dist/slightly-1.1.0.min.js.sri
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256-Nxu7MRVA8V6ScEToIuIigm1STQtOyJ4pmZeYXc8sRjA=
2 changes: 1 addition & 1 deletion public/dist/slightly-latest.dist.js
2 changes: 1 addition & 1 deletion public/dist/slightly-latest.dist.js.sri
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha256-zYSMeqN12wqnxDZwpv+ln00PhAD66KSX/uLouJxHB4M=
sha256-ESoAgVJl33qrPqIzALgkztic05pw+eWw+HP7RjVat3M=
2 changes: 1 addition & 1 deletion public/dist/slightly-latest.min.js
2 changes: 1 addition & 1 deletion public/dist/slightly-latest.min.js.sri
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha256-qLYNxid6oOyVJ4PimnsA/CIsZY/cocQ42yNTrLRb8cI=
sha256-Nxu7MRVA8V6ScEToIuIigm1STQtOyJ4pmZeYXc8sRjA=
2 changes: 1 addition & 1 deletion public/dist/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
<link rel="preload" href="/template/main.css" as="style" />
<link rel="preload" href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" as="style" />

<script defer src="/dist/slightly-1.0.0.min.js" integrity="sha256-qLYNxid6oOyVJ4PimnsA/CIsZY/cocQ42yNTrLRb8cI=" crossorigin></script>
<script defer src="/dist/slightly-1.1.0.min.js" integrity="sha256-Nxu7MRVA8V6ScEToIuIigm1STQtOyJ4pmZeYXc8sRjA=" crossorigin></script>
<meta name="slightly-config" content="/config.json" />
<script>
let path = window.location.pathname === "/" ? "/index.md" : `${window.location.pathname}.md`;
25 changes: 25 additions & 0 deletions public/index.md
Original file line number Diff line number Diff line change
@@ -90,6 +90,31 @@ Content is provided as simple static markdown files, with optional YAML
[frontmatter](#yaml-frontmatter). It should be present on the webserver at the
request path, with a `.md` file extension.

### Images

Images will be rendered inside `<figure>` blocks. If the image has an `alt`
attribute, the contents of that will be appended after the image as a
`<figcaption>`.

Some basic styling of the figure is possible using the fragment portion of the
image URL. This consists of a semicolon-separated set of key / value pairs. The
value is optional.

Any unrecognised key is added to the figure as a class, and the value is
discarded.

![Image caption](/url/of/image.jpg#right;w=50%;my-class)

The above example will display a right-floated figure, 50% wide, with the class
`my-class`.

| Key | Description |
| :------ | :--------------------- |
| `left` | Float the figure left |
| `right` | Float the figure right |
| `w` | Set the figure width |
| `h` | Set the figure height |

### 404 Errors

In order to return the correct HTTP status code, any request for which the
44 changes: 42 additions & 2 deletions src/slightly.js
Original file line number Diff line number Diff line change
@@ -177,8 +177,7 @@ import MarkdownIt from "markdown-it";
description: undefined
};
let matches = md.match(/^(?:---\r?\n\r?(.*)\r?\n\r?---\r?\n\r?)?(.*)/su);
if (!matches)
throw new Error(`Invalid content document: ${mdPath}`);
if (!matches) throw new Error(`Invalid content document: ${mdPath}`);
if (matches[1]) {
let yaml = jsyaml.safeLoad(matches[1]);
for (let key in config) {
@@ -192,6 +191,47 @@ import MarkdownIt from "markdown-it";
let toc = this.toc(content.body);
return { config, content, toc };
})
.then(p => {
// post-process images
p.content.querySelectorAll("img[src*='#']").forEach(img => {
let f = document.createElement("figure");
f.style.maxWidth = img.style.maxWidth;
img.style.maxWidth = "100%";
f.style.maxHeight = img.style.maxHeight;
img.style.maxHeight = "100%";
img.replaceWith(f);
f.appendChild(img);
if (img.alt) {
let c = document.createElement("figcaption");
c.textContent = img.alt;
f.appendChild(c);
}
let [, src, format] = img.src.match(/(.*?)#(.*)/u);
img.src = src;
decodeURI(format)
.split(";")
.forEach(attr => {
let [, key, val] = attr.trim().match(/^(.+?)(?:\s*=\s*(.+))?$/);
switch (key) {
case "left":
case "right":
f.style.float = key;
break;
case "w":
f.style.width = val;
break;
case "h":
f.style.height = val;
break;
default:
f.classList.add(key);
break;
}
});
});

return p;
})
.catch(err => console.log(err))
.catch(err => Promise.reject(new Error(`Unable to fetch content: ${mdPath}`)));
}

0 comments on commit 0338283

Please sign in to comment.