Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple plugin system for schnack #99

Merged
merged 73 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
596f3d1
refactor auth providers into plugins
gka Mar 6, 2019
51e2301
refactor push notifications into notify-plugins
gka Mar 6, 2019
e73e51f
rename push.js to notify.js
gka Mar 6, 2019
62c9199
move notify config into plugins section
gka Mar 6, 2019
d9a7d37
refactor plugin api
gka Mar 11, 2019
ba266fb
add create-schnack package
gka Mar 12, 2019
048d29f
move plugins into schn4ack/schnack-plugins
gka Mar 12, 2019
4cfec33
update license year
gka Mar 12, 2019
05af3eb
correct license ref
gka Mar 12, 2019
4958ee7
update readme
gka Mar 12, 2019
f02266f
update install
gka Mar 12, 2019
da5fc61
create readme
gka Mar 12, 2019
74bf3e9
removed unused dependencies
gka Mar 12, 2019
5203547
tooling and lint
gka Mar 12, 2019
921eda8
update default config
gka Mar 14, 2019
1d7f84d
fix plugin loading
gka Mar 14, 2019
bc639a7
move webpush plugin back to core
gka Mar 14, 2019
34b624a
build files
gka Mar 14, 2019
1ccc500
update dependencies
gka Mar 14, 2019
38e57aa
add bin script "schnack"
gka Mar 14, 2019
833809a
rename config to schnack.json
gka Mar 14, 2019
d0a89e1
use migrations path relative to src/ folder
gka Mar 14, 2019
d08e134
revert to old sqlite versions
gka Mar 14, 2019
cc437c1
show run instructions after npm install is done
gka Mar 14, 2019
594858d
use cwd independent paths to static files
gka Mar 14, 2019
73e2f68
version
gka Mar 14, 2019
3e46b96
1.0.0-0
gka Mar 14, 2019
3120ec3
add bin script
gka Mar 14, 2019
e53522d
version
gka Mar 15, 2019
b109ac1
migration instructions
gka Mar 15, 2019
f1f4d3e
readme
gka Mar 23, 2019
4a61950
move getAuthorUrl responsibility to auth plugins
gka Mar 23, 2019
5e0d0bb
show warning if no auth providers are configured
gka Mar 23, 2019
b38a06a
upgrade marked to 1.1.0
gka May 24, 2020
9453624
rename config.json to schnack.json
gka May 24, 2020
d6e3d59
update sqlite and sqlite3
gka May 24, 2020
6ca0415
check if schnack.json file exists
gka May 24, 2020
5b23985
1.0.0-1
gka May 24, 2020
1314905
update license year
gka Jan 15, 2021
cfac659
add support for custom user plugins via "pkg", document plugins
gka Jan 15, 2021
e2dd5f9
readme
gka Jan 15, 2021
f4bb064
readme
gka Jan 15, 2021
e68bd6b
1.0.0-2
gka Jan 15, 2021
c0ab252
update create-schnack
gka Jan 15, 2021
676b552
ignore notify-webpush (local plugin)
gka Jan 15, 2021
46b849b
fix startup script
gka Jan 15, 2021
598f179
fix sqlite initialization
gka Jan 15, 2021
40ac5b7
1.0.0-3
gka Jan 15, 2021
184c2ae
fix db handler
gka Jan 15, 2021
e42368e
don't overwrite existing package.json file
gka Jan 15, 2021
b75864b
always install latest plugin version
gka Jan 15, 2021
2c31246
fix log instruction
gka Jan 15, 2021
fb6cb75
1.0.0-4
gka Jan 15, 2021
1560cd1
only use promise-api of sqlite
gka Jan 15, 2021
e9a7521
1.0.0-5
gka Jan 15, 2021
efb6c88
use insane sanitizer instead of deprecated built-in marked santize
gka Jan 15, 2021
ad14a6e
1.0.0-6
gka Jan 15, 2021
deed1d1
getAuthorUrl is optional
gka Jan 15, 2021
db425b6
1.0.0-7
gka Jan 15, 2021
84063b1
properly use author_url from db
gka Jan 15, 2021
5e1d08e
1.0.0-8
gka Jan 15, 2021
9417723
update dependencies and rollup build setup
gka Jan 16, 2021
b1e8b12
readme and migration notes
gka Jan 16, 2021
7a0e022
add notify-sendmail to default config
gka Jan 16, 2021
06b1753
interactive schnack setup
gka Jan 16, 2021
db1cc09
bump version
gka Jan 16, 2021
318cfa5
clean up unused packages
gka Jan 16, 2021
fe3eecb
1.0.0-9
gka Jan 16, 2021
42a8bb2
bump version
gka Jan 16, 2021
76ca4e9
hello version 1.0.0
gka Jan 16, 2021
ec38d0b
readme
gka Jan 16, 2021
e380393
fetch default config from master
gka Jan 16, 2021
db62639
migration notes
gka Jan 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/*
yarn.lock
*.db
config.json
schnack.json
npm-debug.log
*.sublime-*
.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The Lil License v1

Copyright (c) 2018 Gregor Aisch, Moritz Klack & g-div
Copyright (c) 2021 Gregor Aisch, Moritz Klack & g-div

Permission is hereby granted by the authors of this software, to any person,
to use the software for any purpose, free of charge, including the rights to
Expand Down
125 changes: 83 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,56 @@

[Schnack](https://dict.leo.org/englisch-deutsch/schnack) is a simple Disqus-like drop-in commenting system written in JavaScript.

* [Documentation](https://schnack.cool/)
* [Say hello to Schnack.js](https://www.vis4.net/blog/2017/10/hello-schnack/)
* Follow [@schnackjs](https://twitter.com/schnackjs) on Twitter
- [Documentation](https://schnack.cool/)
- [Say hello to Schnack.js](https://www.vis4.net/blog/2017/10/hello-schnack/)
- Follow [@schnackjs](https://twitter.com/schnackjs) on Twitter

## What the schnack?

Features:
- Tiny! It takes only ~**8 KB!!!** to embed Schnack.
- **Open source** and **self-hosted**.
- Ad-free and Tracking-free. Schnack will **not disturb your users**.
- It's simpy to moderate, with a **minimal** and **slick UI** to allow/reject comments or trust/block users.
- **[webpush protocol](https://tools.ietf.org/html/draft-ietf-webpush-protocol-12) to notify the site owner** about new comments awaiting for moderation.
- **Third party providers for authentication** like Github, Twitter, Google and Facebook. Users are not required to register a new account on your system and you don't need to manage a user management system.

- Tiny! It takes only ~**8 KB!!!** to embed Schnack.
- **Open source** and **self-hosted**.
- Ad-free and Tracking-free. Schnack will **not disturb your users**.
- It's simpy to moderate, with a **minimal** and **slick UI** to allow/reject comments or trust/block users.
- **[webpush protocol](https://tools.ietf.org/html/draft-ietf-webpush-protocol-12) to notify the site owner** about new comments awaiting for moderation.
- **Third party providers for authentication** like Github, Twitter, Google and Facebook. Users are not required to register a new account on your system and you don't need to manage a user management system.

### Quickstart

This is the fastest way to setup *schnack*.
*Note: If you are updating Schnack from a 0.x version check out the separate [upgrade instructions](docs/migrating-to-schnack-1.md).*

This is the fastest way to setup _schnack_.

**Requirements**:
- Node.js (>= v6)
- npm (>= v5)

Clone or download schnack:
- Node.js (>= v8)
- npm (>= v5)

```bash
git clone https://github.com/schn4ck/schnack
```
Create a new folder for schnack and change into it:

Go to the schnack directory:
```bash
mkdir schnack
cd schnack
npm init schnack
```

Install dependencies:
if there is no `schnack.json` in this folder, the init script copied over the default config and ask you if you want to configure your server interactively.

alternatively you can just edit the config file according to [configuration](https://schnack.cool/#configuration) section:

```bash
npm install
vim schnack.json # or open with any editor of your choice
```

Copy and edit the config file according to [configuration](https://schnack.cool/#configuration) section:
Finally, run `npm init schnack` again to finish installation:

```bash
cp config.tpl.json config.json
vim config.json # or open with any editor of your choice
npm init schnack
```

Run the server:

```bash
npm start
```
Expand All @@ -56,13 +60,14 @@ Embed in your HTML page:

```html
<div class="comments-go-here"></div>
<script src="https://comments.example.com/embed.js"
<script
src="https://comments.example.com/embed.js"
data-schnack-slug="post-slug"
data-schnack-target=".comments-go-here">
</script>
data-schnack-target=".comments-go-here"
></script>
```

**or** initialize *schnack* programmatically:
**or** initialize _schnack_ programmatically:

```html
<div class="comments-go-here"></div>
Expand All @@ -79,15 +84,50 @@ Embed in your HTML page:

You will find further information on the [schnack page](https://schnack.cool/).

### Configuration
### Plugins

**Notify Providers:**
Authentication and notification providers can be added via plugins.

* pushover
* webpush
* slack
* rss
* sendmail
```sh
npm install @schnack/plugin-auth-github @schnack/plugin-auth-google @schnack/plugin-notify-slack
```

To enable the plugins you need to add them to the `plugins` section of your `schnack.json`:

```js
{
// ...
"plugins": {
"auth-github": {
"client_id": "xxxxx",
"client_secret": "xxxxx"
},
"auth-google": {
"client_id": "xxxxx",
"client_secret": "xxxxx"
},
"notify-slack": {
"webhook_url": "xxxxx"
}
}
}
```

if you want to write your own plugins you need to install them and specify their package name in the `schnack.json`. Otherwise Schnack would try to load as from `@schnack/plugin-my-plugin`.

```js
{
// ...
"plugins": {
"my-plugin": {
"pkg": "my-schnack-plugin",
// ...
}
}
}
```

Feel free to open a PR on [schnack-plugins](https://github.com/schn4ck/schnack-plugins) with your plugin if you want to add it to the "official" repository.

### Who is behind Schnack?

Expand All @@ -97,17 +137,18 @@ Schnack is [yet another](https://github.com/gka/canvid/) happy collaboration bet

Schnack will never track who is using it, so we don't know! If you are a Schnack user, [let us know](https://twitter.com/schnackjs) and we'll add your website here. So far Schnack is being used on:

* https://schnack.cool (scroll all the day down)
* https://vis4.net/blog
* https://blog.datawrapper.de
* https://blog.webkid.io
- https://schnack.cool (scroll all the day down)
- https://vis4.net/blog
- https://blog.datawrapper.de
- https://blog.webkid.io

### Related projects

This is not a new idea, so there are a few projects that are doing almost the same thing:

* [CoralProject Talk](https://github.com/coralproject/talk) - Node + MongoDB + Redis
* [Discourse](https://github.com/discourse/discourse) - Ruby on Rails + PostgreSQL + Redis
* [Commento](https://github.com/adtac/commento) - Go + Node
* [Isso](https://github.com/posativ/isso/) - Python + SQLite3
* [Mouthful](https://mouthful.dizzy.zone) – Go + Preact
- [CoralProject Talk](https://github.com/coralproject/talk) - Node + MongoDB + Redis
- [Discourse](https://github.com/discourse/discourse) - Ruby on Rails + PostgreSQL + Redis
- [Commento](https://github.com/adtac/commento) - Go + Node
- [Isso](https://github.com/posativ/isso/) - Python + SQLite3
- [Mouthful](https://mouthful.dizzy.zone) – Go + Preact

2 changes: 1 addition & 1 deletion build/client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/embed.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions create-schnack/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The Lil License v1

Copyright (c) 2019 Gregor Aisch, Moritz Klack & g-div

Permission is hereby granted by the authors of this software, to any person,
to use the software for any purpose, free of charge, including the rights to
run, read, copy, change, distribute and sell it, and including usage rights to
any patents the authors may hold on it, subject to the following conditions:

This license, or a link to its text, must be included with all copies of the
software and any derivative works.

Any modification to the software submitted to the authors may be incorporated
into the software under the terms of this license.

The software is provided "as is", without warranty of any kind, including but
not limited to the warranties of title, fitness, merchantability and non-
infringement. The authors have no obligation to provide support or updates for
the software, and may not be held liable for any damages, claims or other
liability arising from its use.
53 changes: 53 additions & 0 deletions create-schnack/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! /usr/bin/env node
/* eslint no-console: "off" */
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
const setup = require('./setup');
const { white, green } = require('chalk');

const CWD = process.env.INIT_CWD || process.cwd();
let tag = process.argv.find(arg => arg.includes('--tag')) || '--tag=latest';
tag = tag.split('=')[1];

async function main() {
const configPath = path.join(CWD, 'schnack.json');

if (!fs.existsSync(configPath)) {
await setup();
}

const { plugins, schnack_host } = require(configPath);

// create package.json file if it doesn't exist
if (!fs.existsSync(path.join(CWD, 'package.json'))) {
console.log(`[init] Initialize ${green('package.json')} file.`);
const pkg = {
name: schnack_host.replace(/https?:\/\//, ''),
version: '1.0.0',
private: true,
scripts: {
start: 'schnack'
}
};
fs.writeFileSync(path.join(CWD, 'package.json'), JSON.stringify(pkg, null, 4), {
encoding: 'utf-8'
});
}

const packages = Object.keys(plugins || {})
.filter(id => id !== 'notify-webpush')
.map(id => `${plugins[id].pkg || `@schnack/plugin-${id}`}@latest`);

console.log('[npm] Start package installation.');
const npm = spawn('npm', ['install', '-SE', '--production', `schnack@${tag}`].concat(packages));

npm.stdout.on('data', data => process.stdout.write(data));
npm.stderr.on('data', data => process.stderr.write(data));

npm.on('close', () => {
console.log(`\nrun ${white('npm start')} to start your Schnack server.`);
});
}

main();
Loading