Skip to content

Commit

Permalink
Merge branch 'main' into remove-seo-json
Browse files Browse the repository at this point in the history
  • Loading branch information
andypiper authored Jan 24, 2024
2 parents 8187284 + b09b248 commit 5955cd8
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 4 deletions.
48 changes: 46 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"sqlite": "^5.0.1",
"sqlite3": "^5.1.5",
"string-strip-html": "^13.4.2",
"escape-html": "^1.0.3"
"escape-html": "^1.0.3",
"xml2js": "^0.6.2"
},
"engines": {
"node": ">=16.x"
Expand All @@ -43,7 +44,8 @@
"fediverse",
"express",
"activitypub",
"mastodon"
"mastodon",
"bookmarks"
],
"devDependencies": {
"eslint": "^8.43.0",
Expand Down
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const hbs = create({
projectUrl() {
return `https://${app.get('domain')}`;
},
searchUrl() {
return `https://${app.get('domain')}/opensearch.xml`;
},
glitchProjectName() {
return process.env.PROJECT_DOMAIN;
},
Expand Down Expand Up @@ -125,5 +128,6 @@ app.use('/', routes.core);
app.use('/api/inbox', cors(), routes.inbox);
app.use('/.well-known/nodeinfo', routes.nodeinfo);
app.use('/nodeinfo/2.0', routes.nodeinfo);
app.use('/opensearch.xml', routes.opensearch);

app.listen(PORT, () => console.log(`App listening on port ${PORT}`));
1 change: 1 addition & 0 deletions src/pages/layouts/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<title>{{title}} | {{siteName}}</title>
<link rel="apple-touch-icon" sizes="180x180" href="https://cdn.glitch.global/8eaf209c-2fa9-4353-9b99-e8d8f3a5f8d4/postmarks-touch-icon-180.png?v=1693611327251">
<link rel="shortcut icon" href="https://cdn.glitch.global/8eaf209c-2fa9-4353-9b99-e8d8f3a5f8d4/postmarks-favicon.ico?v=1693611323474">
<link rel="search" type="application/opensearchdescription+xml" href="{{{searchUrl}}}" title="Postmarks">
<link rel="stylesheet" href="/style.css">
</head>
<body>
Expand Down
2 changes: 2 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import message from './activitypub/message.js';
import user from './activitypub/user.js';
import webfinger from './activitypub/webfinger.js';
import nodeinfo from './activitypub/nodeinfo.js';
import opensearch from './opensearch.js';

export default {
admin,
Expand All @@ -20,4 +21,5 @@ export default {
user,
webfinger,
nodeinfo,
opensearch,
};
53 changes: 53 additions & 0 deletions src/routes/opensearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import express from 'express';
import xml2js from 'xml2js';

const router = express.Router();

router.get('/', async (req, res) => {
const domain = req.app.get('domain');
const searchUrl = `https://${domain}/search`;

const obj = {
OpenSearchDescription: {
$: {
xmlns: 'http://a9.com/-/spec/opensearch/1.1/',
'xmlns:moz': 'http://www.mozilla.org/2006/browser/search/',
},
ShortName: 'Postmarks',
Description: 'Search your Postmarks',
InputEncoding: 'UTF-8',
Image: {
$: {
width: '16',
height: '16',
type: 'image/png',
},
_: 'https://cdn.glitch.global/8eaf209c-2fa9-4353-9b99-e8d8f3a5f8d4/postmarks-favicon.ico?v=1693611323474',
},
Url: {
$: {
type: 'text/html',
method: 'get',
template: `${searchUrl}?query={searchTerms}&ref=opensearch`,
},
},
'moz:SearchForm': {
_: `${searchUrl}`,
},
Query: {
$: {
role: 'example',
searchTerms: 'postmarks',
},
},
},
};

const builder = new xml2js.Builder({ headless: true });
const xml = builder.buildObject(obj);

res.header('Content-Type', 'application/opensearchdescription+xml');
res.status(200).send(xml);
});

export default router;

0 comments on commit 5955cd8

Please sign in to comment.