Compare commits

..

No commits in common. "99637521d4e40f158fbbc4698b724d7d2aab5f92" and "3be13e191e08a12c5fca05254e6e3869692d6325" have entirely different histories.

11 changed files with 28 additions and 118 deletions

View File

@ -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 = !actorObject.icon ? null : actorObject.icon instanceof Array ? getIconUrl(actorObject.icon[0]) : getIconUrl(actorObject.icon); const iconURL: string = 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;

View File

@ -4,7 +4,6 @@ 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 = {
@ -14,6 +13,5 @@ export = {
federate, federate,
followers, followers,
inbox, inbox,
nodeinfo,
webfinger webfinger
}; };

View File

@ -1,59 +0,0 @@
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,7 +34,5 @@ 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);
}
} }

View File

@ -1,20 +0,0 @@
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 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,

15
lib/generate/missing.ts Normal file
View File

@ -0,0 +1,15 @@
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[]> { async function generate(): Promise<Page[]> {
generators.copy(); generators.copy();
generators.css(); generators.css();
generators.errors(); generators.missing();
const tutorials = await generators.tutorials(); const tutorials = await generators.tutorials();
@ -68,23 +68,11 @@ 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}`);

View File

@ -3,7 +3,7 @@ metadata.title = "Not Found"
metadata.layout = "default.html.ejs" metadata.layout = "default.html.ejs"
``` ```
<div class="main error-page"> <div class="main search">
<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">

View File

@ -1,11 +0,0 @@
```
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 {
} }
} }
.error-page { .search {
margin: 0 auto; margin: 100px auto;
text-align: center; text-align: center;
h3 { h3 {
@ -205,6 +205,7 @@ 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 {