Compare commits

..

4 Commits

Author SHA1 Message Date
Shadowfacts 99637521d4
Only enable Sass watcher in development 2019-09-17 15:34:48 -04:00
Shadowfacts 5b307675b1
Fix error pages 2019-09-17 15:30:47 -04:00
Shadowfacts 38b8c34a05
Add nodeinfo support 2019-09-17 14:36:54 -04:00
Shadowfacts 8490156176
Handle actors w/o icons 2019-09-17 14:19:02 -04:00
11 changed files with 118 additions and 28 deletions

View File

@ -60,7 +60,7 @@ async function cacheActor(actorObject: ActorObject) {
function getIconUrl(icon: string | object): string {
return icon instanceof String ? icon : (icon as any).url;
}
const iconURL: string = actorObject.icon instanceof Array ? getIconUrl(actorObject.icon[0]) : getIconUrl(actorObject.icon);
const iconURL = !actorObject.icon ? null : actorObject.icon instanceof Array ? getIconUrl(actorObject.icon[0]) : getIconUrl(actorObject.icon);
const actor = new Actor();
actor.id = actorObject.id;
actor.actorObject = actorObject;

View File

@ -4,6 +4,7 @@ import comments from "./comments";
import federate from "./federate";
import followers from "./followers";
import inbox from "./inbox";
import nodeinfo from "./nodeinfo";
import webfinger from "./webfinger";
export = {
@ -13,5 +14,6 @@ export = {
federate,
followers,
inbox,
nodeinfo,
webfinger
};

View File

@ -0,0 +1,59 @@
import {Request, Response, Router} from "express";
import { promises as fs } from "fs";
import {getConnection} from "typeorm";
import Article from "../entity/Article";
import Note from "../entity/Note";
const domain = process.env.DOMAIN;
export default async function nodeinfo(router: Router) {
router.get("/.well-known/nodeinfo", (req, res) => {
res.json({
links: [
{
href: `https://${domain}/nodeinfo/2.0.json`,
rel: "https://nodeinfo.diaspora.software/ns/schema/2.0"
},
{
href: `https://${domain}/nodeinfo/2.1.json`,
rel: "https://nodeinfo.diaspora.software/ns/schema/2.1"
}
]
});
res.end();
});
router.get("/nodeinfo/2.0.json", await handleNodeInfo("2.0"));
router.get("/nodeinfo/2.1.json", await handleNodeInfo("2.1"));
}
async function handleNodeInfo(version: string) {
const softwareVersion = JSON.parse((await fs.readFile("package.json")).toString()).version;
const postCount = await getConnection().getRepository(Article).count();
return async (req: Request, res: Response) => {
res.json({
version: version,
software: {
name: "shadowfacts_blog",
version: softwareVersion,
repository: version === "2.1" ? "https://git.shadowfacts.net/shadowfacts/shadowfacts.net" : undefined
},
protocols: ["activitypub"],
services: {
inbound: [],
outbound: ["atom1.0"]
},
openRegistrations: false,
usage: {
users: {
total: 1,
activeHalfyear: 1,
activeMonth: 1
},
localPosts: postCount,
localComments: await getConnection().getRepository(Note).count()
}
});
res.end();
};
}

View File

@ -34,5 +34,7 @@ export default async function css() {
await generate("dark");
await generate("auto");
if (process.env.NODE_ENV === "development") {
require("fs").watch("site/css/", css);
}
}

20
lib/generate/errors.ts Normal file
View File

@ -0,0 +1,20 @@
import * as metadata from "../metadata";
import layout from "../layout";
import * as util from "../util";
export default async function errors() {
await generate("404.html");
await generate("500.html");
}
async function generate(filename: string) {
const page = await metadata.get(`site/${filename}.ejs`);
page.text = util.render(page.text, {
metadata: page.metadata
}, `site/${filename}.ejs`);
page.text = await layout(page.text, page.metadata, page.metadata.layout!);
await util.write(filename, page.text);
}

View File

@ -1,8 +1,8 @@
import categories from "./categories";
import copy from "./copy";
import css from "./css";
import errors from "./errors";
import homepage from "./homepage";
import missing from "./missing";
import posts from "./posts";
import redirects from "./redirects";
import rss from "./rss";
@ -12,8 +12,8 @@ export = {
categories,
copy,
css,
errors,
homepage,
missing,
posts,
redirects,
rss,

View File

@ -1,15 +0,0 @@
import * as metadata from "../metadata";
import layout from "../layout";
import * as util from "../util";
export default async function missing() {
const page = await metadata.get("site/404.html.ejs");
page.text = util.render(page.text, {
metadata: page.metadata
}, "site/404.html.ejs");
page.text = await layout(page.text, page.metadata, page.metadata.layout!);
util.write("404.html", page.text);
}

View File

@ -14,7 +14,7 @@ import * as path from "path";
async function generate(): Promise<Page[]> {
generators.copy();
generators.css();
generators.missing();
generators.errors();
const tutorials = await generators.tutorials();
@ -68,11 +68,23 @@ async function generate(): Promise<Page[]> {
activitypub.comments(apRouter);
activitypub.followers(apRouter);
activitypub.inbox(apRouter);
await activitypub.nodeinfo(apRouter);
activitypub.webfinger(apRouter);
activitypub.articles.route(apRouter);
app.use(apRouter);
app.use(express.static("out"));
app.use((err, req, res, next) => {
res.status(500).sendFile("500.html", {
root: "out"
});
});
app.use((req, res, next) => {
res.status(404).sendFile("404.html", {
root: "out"
});
});
const port = process.env.PORT || 8083;
app.listen(port, () => {
console.log(`Listening on port ${port}`);

View File

@ -3,7 +3,7 @@ metadata.title = "Not Found"
metadata.layout = "default.html.ejs"
```
<div class="main search">
<div class="main error-page">
<h1 class="page-heading">Unable to find what you were looking for.</h1>
<h3>Try searching:</h3>
<form action="https://www.google.com/search" method="GET">

11
site/500.html.ejs Normal file
View File

@ -0,0 +1,11 @@
```
metadata.title = "Not Found"
metadata.layout = "default.html.ejs"
```
<div class="main error-page">
<h1 class="page-heading">Something went wrong.</h1>
<p>
Please try again later. If the error persists, please <a href="mailto:me@shadowfacts.net">contact me</a>.
</p>
</div>

View File

@ -195,8 +195,8 @@ article {
}
}
.search {
margin: 100px auto;
.error-page {
margin: 0 auto;
text-align: center;
h3 {
@ -205,7 +205,6 @@ article {
line-height: 1.3;
text-align: center;
margin: 0;
padding: 0 2rem;
}
input#q {