# Wiki sync plugin

**URL:** https://meta.discourse.org/t/wiki-sync-plugin/48946
**Category:** Development
**Created:** [August 21, 2016, 12:39pm UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946 "2016-08-21T12:39:53Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Lapinot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lapinot/32/60809_2.png) [@Lapinot](https://meta.discourse.org/u/Lapinot)
#### Post date: [August 21, 2016, 12:39pm UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/1 "2016-08-21T12:39:53Z")

</div>

Hi everyone, I had an idea of a simple plugin that I am going to write but I may need some help/advices.

The idea is just to sync up the posts in wiki mode with some external version control (a git server). This is really simple if there is a server-side discourse hook like `after-edit-post` or something similar but I can’t find it. My use case is that I don’t like CMSs but I need a collaboratively built website (kinda like a wiki) so I would like to have a automatically run static site generator on top of some git repo. The problem is that lots of people don’t know how to use version control systems and that we already have a healthy discourse instance. This plugin would enable a very simple workflow: just post a a mesage in wiki mode and it will be committed (as well as any subsequent edit) to the git repository in some directory depending on the category. From there it can be used for automatic builds of the static site (or could maybe also be used by a gollum wiki or any other documentation system).

I don’t think this kind of thing has already been developped and I am not very familiar with ruby so I couldn’t really find my way in the source code. Does this sound good and would it be easy to implement?

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [August 21, 2016, 11:16pm UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/2 "2016-08-21T23:16:31Z")

</div>

There have been wistful mentions of things like this before, but as far as I know nobody’s developed anything for public release. It sounds like it could be useful, and whether it’s “easy to implement” is entirely in the eye of the beholder… 😀

---

<div class="post-metadata">

### Author: ![Lapinot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lapinot/32/60809_2.png) [@Lapinot](https://meta.discourse.org/u/Lapinot)
#### Post date: [August 22, 2016, 9:27am UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/3 "2016-08-22T09:27:07Z")

</div>

Thanks for the answer! Actually my question about _easyness_ was not very clear… I meant: what do I have to do in order to get some piece of code called server-side every time a (wiki mode) post gets edited? Is there already a hook somewhere or do I have to actually make a pull request and fiddle with the core discourse code (add some code in `discourse/app/controllers/posts_controller.rb`)?

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [August 22, 2016, 9:58am UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/4 "2016-08-22T09:58:27Z")

</div>

Are you aware that Discourse supports enabling “wiki” for selected posts? These posts are tracked for changes (there is even highlighted diff shown publicly)… (To be sure check for exact implementation - I don’t know about its limitations).

I don’t know if its good for your case, but I’d definitely use this core feature and just use Discourse API to present Wiki somewhere else… Then you can skip the git.

---

<div class="post-metadata">

### Author: ![Lapinot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lapinot/32/60809_2.png) [@Lapinot](https://meta.discourse.org/u/Lapinot)
#### Post date: [August 22, 2016, 10:04am UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/5 "2016-08-22T10:04:02Z")

</div>

I mentionned it 😉 The problem with that is that I want to feed these markdown files into a static site generator (or something similar) so if I don’t have hooks and custom versionning, I wouldn’t know when posts have changed and I must regenerate the site. But maybe you’re right, I should just periodically scan for changes with the API and rebuild if necessary, it could be cleaner.

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [August 22, 2016, 10:04am UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/6 "2016-08-22T10:04:28Z")

</div>

You can see an example of a similar setup here:

> [@Using Discourse as a community-powered wiki](https://meta.discourse.org/t/using-discourse-as-a-community-powered-wiki/43599):
>
> The following is a guest post by Sam Nazarko, CEO and founder of [OSMC.tv](http://OSMC.tv) Are you using Discourse in a novel way? If you’re interested in writing a guest post like this one, please get in touch. In 2014, I started working on a new project, OSMC (Open Source Media Center). OSMC is a free and… This topic is for comments on the original blog entry at: [Using Discourse as a community-powered wiki](http://blog.discourse.org/2016/05/using-discourse-as-a-community-powered-wiki/)

There’s also the [LearnDiscourse experiment](https://meta.discourse.org/t/unofficial-community-docs-learndiscourse-org/31931). You can get an idea of how it worked by reading the [workflow doc](https://github.com/erlend-sh/learndiscourse/blob/gh-pages/about.md). I think @fantasticfears who worked on the learndiscourse prototype ran into the same limitation you did, which is why we settled with

> Your changes will be applied the next time we update [learndiscourse.org](http://learndiscourse.org), which usually happens at least once every week.

You might also run into this problem:

> [@Working with different needs in raw/cooked content](https://meta.discourse.org/t/working-with-different-needs-in-raw-cooked-content/46723):
>
> I’m using only the API of Discourse with a custom UI. I want to support some custom Markdown extensions which I’d like the “cooked” content of a post to honor. I think there are probably a few ways to do this: Get Discourse to use a custom Markdown parser When posting, convert the Markdown to HTML before submitting it to the Discourse API Getting access to the “raw” post in addition to the “cooked” post after it’s been submitted 1 won’t work for me if it requires a code change to Discourse, …

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [August 22, 2016, 10:08am UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/7 "2016-08-22T10:08:51Z")

</div>

Why this needs to be static in the first place?

I’m working on something similar…

Using rails and ember.js you can just expand current Discourse application and build simple presentation model (wiki category \>\< post).

But of course its the matter of personal taste 🙂

---

<div class="post-metadata">

### Author: ![Lapinot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lapinot/32/60809_2.png) [@Lapinot](https://meta.discourse.org/u/Lapinot)
#### Post date: [August 22, 2016, 10:14am UTC](https://meta.discourse.org/t/wiki-sync-plugin/48946/8 "2016-08-22T10:14:58Z")

</div>

@erlend_sh Nice, I totally missed these topics while researching around meta.. Learndiscourse seems like the exact same thing I want to achieve, I will take a closer look and probably take it as base. It seems like querying discourse periodically with the API is the way to go.

@Overgrow The advantages of being static is that you have much better performance and security. And actually, my content is not going to change so often (I think one rebuild every day will really be enough). Moreover I am not really fluent in ruby (agreed, syntax is simple, especially coming from python) and really not used to frontend development.

Edit: I started doing some bot periodic scanning/watching of the topics with a python scripts using the discourse API but I just stumbled over this topic:

> [@Configure webhooks that trigger on Discourse events to integrate with external services](https://meta.discourse.org/t/setting-up-webhooks/49045):
>
> A webhook is a way to notify external services about changes on the internet. It’s easier to setup, manage and develop than a Discourse plugin. Though, it does require you to program a little bit or understand its technical details. In this #howto, I’ll set up webhook to power a Github bot for referencing pull request brought in a forum. We’ll want to see a new comment on Github pull request when a new post has a link to it. It’s a very simple process: Publish a new post. A webhook event happ…

It might be the exact thing I want: some server side hook watching for topic/posts edit events.
