Compare commits
4 Commits
3be13e191e
...
99637521d4
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 99637521d4 | |
Shadowfacts | 5b307675b1 | |
Shadowfacts | 38b8c34a05 | |
Shadowfacts | 8490156176 |
|
@ -60,7 +60,7 @@ async function cacheActor(actorObject: ActorObject) {
|
||||||
function getIconUrl(icon: string | object): string {
|
function getIconUrl(icon: string | object): string {
|
||||||
return icon instanceof String ? icon : (icon as any).url;
|
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();
|
const actor = new Actor();
|
||||||
actor.id = actorObject.id;
|
actor.id = actorObject.id;
|
||||||
actor.actorObject = actorObject;
|
actor.actorObject = actorObject;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import comments from "./comments";
|
||||||
import federate from "./federate";
|
import federate from "./federate";
|
||||||
import followers from "./followers";
|
import followers from "./followers";
|
||||||
import inbox from "./inbox";
|
import inbox from "./inbox";
|
||||||
|
import nodeinfo from "./nodeinfo";
|
||||||
import webfinger from "./webfinger";
|
import webfinger from "./webfinger";
|
||||||
|
|
||||||
export = {
|
export = {
|
||||||
|
@ -13,5 +14,6 @@ export = {
|
||||||
federate,
|
federate,
|
||||||
followers,
|
followers,
|
||||||
inbox,
|
inbox,
|
||||||
|
nodeinfo,
|
||||||
webfinger
|
webfinger
|
||||||
};
|
};
|
|
@ -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();
|
||||||
|
};
|
||||||
|
}
|
|
@ -34,5 +34,7 @@ export default async function css() {
|
||||||
await generate("dark");
|
await generate("dark");
|
||||||
await generate("auto");
|
await generate("auto");
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === "development") {
|
||||||
require("fs").watch("site/css/", css);
|
require("fs").watch("site/css/", css);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import categories from "./categories";
|
import categories from "./categories";
|
||||||
import copy from "./copy";
|
import copy from "./copy";
|
||||||
import css from "./css";
|
import css from "./css";
|
||||||
|
import errors from "./errors";
|
||||||
import homepage from "./homepage";
|
import homepage from "./homepage";
|
||||||
import missing from "./missing";
|
|
||||||
import posts from "./posts";
|
import posts from "./posts";
|
||||||
import redirects from "./redirects";
|
import redirects from "./redirects";
|
||||||
import rss from "./rss";
|
import rss from "./rss";
|
||||||
|
@ -12,8 +12,8 @@ export = {
|
||||||
categories,
|
categories,
|
||||||
copy,
|
copy,
|
||||||
css,
|
css,
|
||||||
|
errors,
|
||||||
homepage,
|
homepage,
|
||||||
missing,
|
|
||||||
posts,
|
posts,
|
||||||
redirects,
|
redirects,
|
||||||
rss,
|
rss,
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
14
lib/index.ts
14
lib/index.ts
|
@ -14,7 +14,7 @@ import * as path from "path";
|
||||||
async function generate(): Promise<Page[]> {
|
async function generate(): Promise<Page[]> {
|
||||||
generators.copy();
|
generators.copy();
|
||||||
generators.css();
|
generators.css();
|
||||||
generators.missing();
|
generators.errors();
|
||||||
|
|
||||||
const tutorials = await generators.tutorials();
|
const tutorials = await generators.tutorials();
|
||||||
|
|
||||||
|
@ -68,11 +68,23 @@ async function generate(): Promise<Page[]> {
|
||||||
activitypub.comments(apRouter);
|
activitypub.comments(apRouter);
|
||||||
activitypub.followers(apRouter);
|
activitypub.followers(apRouter);
|
||||||
activitypub.inbox(apRouter);
|
activitypub.inbox(apRouter);
|
||||||
|
await activitypub.nodeinfo(apRouter);
|
||||||
activitypub.webfinger(apRouter);
|
activitypub.webfinger(apRouter);
|
||||||
activitypub.articles.route(apRouter);
|
activitypub.articles.route(apRouter);
|
||||||
app.use(apRouter);
|
app.use(apRouter);
|
||||||
app.use(express.static("out"));
|
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;
|
const port = process.env.PORT || 8083;
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Listening on port ${port}`);
|
console.log(`Listening on port ${port}`);
|
||||||
|
|
|
@ -3,7 +3,7 @@ metadata.title = "Not Found"
|
||||||
metadata.layout = "default.html.ejs"
|
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>
|
<h1 class="page-heading">Unable to find what you were looking for.</h1>
|
||||||
<h3>Try searching:</h3>
|
<h3>Try searching:</h3>
|
||||||
<form action="https://www.google.com/search" method="GET">
|
<form action="https://www.google.com/search" method="GET">
|
||||||
|
|
|
@ -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>
|
|
@ -195,8 +195,8 @@ article {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.search {
|
.error-page {
|
||||||
margin: 100px auto;
|
margin: 0 auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
|
@ -205,7 +205,6 @@ article {
|
||||||
line-height: 1.3;
|
line-height: 1.3;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0 2rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input#q {
|
input#q {
|
||||||
|
|
Loading…
Reference in New Issue