Permalink
Browse files

Granary links and notifications (fix #6)

  • Loading branch information...
myfreeweb committed Oct 30, 2017
1 parent 54a75b6 commit 5e0f306a37a099064fb0e44b109d6a7cc4ea8430
Showing with 19 additions and 2 deletions.
  1. +2 −1 README.md
  2. +13 −1 sweetroll-fe/lib/app.js
  3. +2 −0 sweetroll-fe/views/_layout.pug
  4. +2 −0 sweetroll-site.nginx.conf
View
@@ -11,6 +11,7 @@ A powerful engine for [your personal website].
- lets you use Markdown for post text, with nice [code highlighting](https://github.com/ben-eb/remark-highlight.js) and [math rendering](https://github.com/Rokt33r/remark-math)
- the included admin panel (micro-panel) itself uses Micropub
- sends [WebSub] \(formerly PubSubHubbub) notifications on new posts (for [readers])
- uses [Granary] to provide content as Atom, ActivityStreams 2.0 and JSON Feed (with WebSub notifications too)
- represents *all the things* as [Microformats2] objects
- uses PostgreSQL with the [mf2sql] schema for storage
- consists of services written in [Haskell] and [Node.js]
@@ -28,6 +29,7 @@ I'm running it on [my website](https://unrelenting.technology).
[Salmentions]: https://indieweb.org/Salmention
[WebSub]: https://indieweb.org/WebSub
[readers]: https://indieweb.org/readers
[Granary]: https://granary-demo.appspot.com
## Usage
@@ -65,7 +67,6 @@ TODO same for frontend
## TODO
- frontend
- [ ] bring back the atom feed
- [ ] webhooks (e.g. pushover notifications) on new/updated mentions, config in `site-settings`
- micropub
- [ ] draft flag → draft tag and private acl
View
@@ -9,7 +9,7 @@ const webpush = require('web-push')
const qs = require('qs')
const Retry = require('promised-retry')
const _ = require('lodash')
const { head, merge, concat, get, isObject, groupBy, includes, isString, debounce, some } = _
const { head, merge, concat, get, isObject, groupBy, includes, isString, debounce, some, flatMap } = _
const pify = require('pify')
const pug = require('pug')
const pugTryCatch = require('pug-plugin-try-catch')
@@ -27,6 +27,7 @@ const cacheTemplates = env.CACHE_TEMPLATES // Do not recompile templates on ever
const cache = env.DO_CACHE ? require('lru-cache')({
max: parseInt(env.CACHE_MAX_ITEMS || '128')
}) : null
const granaryUrl = env.GRANARY_URL || 'https://granary-demo.appspot.com/url'
const websubHub = env.WEBSUB_HUB || 'https://switchboard.p3k.io'
const websubHubMode = env.WEBSUB_HUB_MODE || 'multi' // Whether to do one request for all URLs affected by a change or one request per URL
const indieAuthEndpoint = env.INDIEAUTH_ENDPOINT || 'https://indieauth.com/auth'
@@ -52,6 +53,12 @@ const pugRender = pify(pug.renderFile)
const render = async (file, tplctx) =>
pugRender('views/' + file, tplctx)
const granaries = [
{ base: `${granaryUrl}?input=html&output=as2&hub=${encodeURIComponent(websubHub)}`, type: 'application/activity+json' },
{ base: `${granaryUrl}?input=html&output=atom&hub=${encodeURIComponent(websubHub)}`, type: 'application/atom+xml' },
{ base: `${granaryUrl}?input=html&output=jsonfeed&hub=${encodeURIComponent(websubHub)}`, type: 'application/json' },
]
const affectedUrls = async (url) => {
const norm = new URI(url).normalizePort().normalizeHostname()
const objUriStr = norm.clone().toString()
@@ -152,9 +159,13 @@ const onEntryChange = async (eventUrl) => {
}
if (websubHubMode === 'multi') {
pushWebSub(affUrls)
pushWebSub(flatMap(affUrls, url => flatMap(granaries, ({base}) => `${base}&url=${encodeURIComponent(url)}`)))
} else {
for (const url of affUrls) {
pushWebSub(url)
for (const { base } of granaries) {
pushWebSub(`${base}&url=${encodeURIComponent(url)}`)
}
}
}
@@ -380,6 +391,7 @@ const addCommonContext = async (ctx, next) => {
indieAuthEndpoint,
microPanelRoot,
vapidKeys,
granaries,
// Pug settings
basedir,
pretty: true,
@@ -21,6 +21,8 @@ html(lang=_.get(siteSettings, 'site-lang', 'en'))
if domainUri
link(rel="openid.delegate" href=domainUri.toString())
link(rel="openid.server" href="https://openid.indieauth.com/openid")
each fmtlink in granaries
link(rel="alternate" type=fmtlink.type href=`${fmtlink.base}&url=${encodeURIComponent(reqUri.toString())}`)
if authedAsAdmin
link(rel='import' href=(microPanelRoot === '/dist/micro-panel' ? assets.url('dist/micro-panel/src/micro-panel.html') : microPanelRoot + '/src/micro-panel.html'))
link(rel='manifest' href=(microPanelRoot === '/dist/micro-panel' ? assets.url('dist/micro-panel/manifest.json') : microPanelRoot + '/manifest.json'))
@@ -22,6 +22,8 @@ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
#proxy_set_header X-Forwarded-Proto 'https';
rewrite ^/.well-known/(host-meta|webfinger).* https://fed.brid.gy$request_uri redirect;
location ~ /(webmention|micropub|login) {
limit_req zone=be burst=20 nodelay;
add_header Content-Security-Policy "default-src 'none'; frame-ancestors 'none'";

0 comments on commit 5e0f306

Please sign in to comment.