diff --git a/content/archives/2020/01/_index.id.md b/content/archives/2020/01/_index.id.md new file mode 100644 index 0000000..1d250a6 --- /dev/null +++ b/content/archives/2020/01/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Jan +--- diff --git a/content/archives/2020/01/_index.md b/content/archives/2020/01/_index.md new file mode 100644 index 0000000..1d250a6 --- /dev/null +++ b/content/archives/2020/01/_index.md @@ -0,0 +1,3 @@ +--- +title: Jan +--- diff --git a/content/archives/2020/02/_index.id.md b/content/archives/2020/02/_index.id.md new file mode 100644 index 0000000..0845d32 --- /dev/null +++ b/content/archives/2020/02/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Feb +--- diff --git a/content/archives/2020/02/_index.md b/content/archives/2020/02/_index.md new file mode 100644 index 0000000..0845d32 --- /dev/null +++ b/content/archives/2020/02/_index.md @@ -0,0 +1,3 @@ +--- +title: Feb +--- diff --git a/content/archives/2020/03/_index.id.md b/content/archives/2020/03/_index.id.md new file mode 100644 index 0000000..c24f274 --- /dev/null +++ b/content/archives/2020/03/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Mar +--- diff --git a/content/archives/2020/03/_index.md b/content/archives/2020/03/_index.md new file mode 100644 index 0000000..c24f274 --- /dev/null +++ b/content/archives/2020/03/_index.md @@ -0,0 +1,3 @@ +--- +title: Mar +--- diff --git a/content/archives/2020/04/_index.id.md b/content/archives/2020/04/_index.id.md new file mode 100644 index 0000000..192ce3e --- /dev/null +++ b/content/archives/2020/04/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Apr +--- diff --git a/content/archives/2020/04/_index.md b/content/archives/2020/04/_index.md new file mode 100644 index 0000000..192ce3e --- /dev/null +++ b/content/archives/2020/04/_index.md @@ -0,0 +1,3 @@ +--- +title: Apr +--- diff --git a/content/archives/2020/05/_index.id.md b/content/archives/2020/05/_index.id.md new file mode 100644 index 0000000..a826ddd --- /dev/null +++ b/content/archives/2020/05/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Mei +--- diff --git a/content/archives/2020/05/_index.md b/content/archives/2020/05/_index.md new file mode 100644 index 0000000..44969e8 --- /dev/null +++ b/content/archives/2020/05/_index.md @@ -0,0 +1,3 @@ +--- +title: May +--- diff --git a/content/archives/2020/06/_index.id.md b/content/archives/2020/06/_index.id.md new file mode 100644 index 0000000..4f4f4d8 --- /dev/null +++ b/content/archives/2020/06/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Jun +--- diff --git a/content/archives/2020/06/_index.md b/content/archives/2020/06/_index.md new file mode 100644 index 0000000..aab6602 --- /dev/null +++ b/content/archives/2020/06/_index.md @@ -0,0 +1,3 @@ +--- +title: Jun +--- diff --git a/content/archives/2020/07/_index.id.md b/content/archives/2020/07/_index.id.md new file mode 100644 index 0000000..f4712e4 --- /dev/null +++ b/content/archives/2020/07/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Jul +--- diff --git a/content/archives/2020/07/_index.md b/content/archives/2020/07/_index.md new file mode 100644 index 0000000..f23a5e8 --- /dev/null +++ b/content/archives/2020/07/_index.md @@ -0,0 +1,3 @@ +--- +title: Jul +--- diff --git a/content/archives/2020/08/_index.id.md b/content/archives/2020/08/_index.id.md new file mode 100644 index 0000000..1338d21 --- /dev/null +++ b/content/archives/2020/08/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Agu +--- diff --git a/content/archives/2020/08/_index.md b/content/archives/2020/08/_index.md new file mode 100644 index 0000000..cf28ed7 --- /dev/null +++ b/content/archives/2020/08/_index.md @@ -0,0 +1,3 @@ +--- +title: Aug +--- diff --git a/content/archives/2020/09/_index.id.md b/content/archives/2020/09/_index.id.md new file mode 100644 index 0000000..640fdd1 --- /dev/null +++ b/content/archives/2020/09/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Sep +--- diff --git a/content/archives/2020/09/_index.md b/content/archives/2020/09/_index.md new file mode 100644 index 0000000..640fdd1 --- /dev/null +++ b/content/archives/2020/09/_index.md @@ -0,0 +1,3 @@ +--- +title: Sep +--- diff --git a/content/archives/2020/10/_index.id.md b/content/archives/2020/10/_index.id.md new file mode 100644 index 0000000..8422ca4 --- /dev/null +++ b/content/archives/2020/10/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Okt +--- diff --git a/content/archives/2020/10/_index.md b/content/archives/2020/10/_index.md new file mode 100644 index 0000000..c22d921 --- /dev/null +++ b/content/archives/2020/10/_index.md @@ -0,0 +1,3 @@ +--- +title: Oct +--- diff --git a/content/archives/2020/11/_index.id.md b/content/archives/2020/11/_index.id.md new file mode 100644 index 0000000..0845d32 --- /dev/null +++ b/content/archives/2020/11/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Feb +--- diff --git a/content/archives/2020/11/_index.md b/content/archives/2020/11/_index.md new file mode 100644 index 0000000..fc74b97 --- /dev/null +++ b/content/archives/2020/11/_index.md @@ -0,0 +1,3 @@ +--- +title: Nov +--- diff --git a/content/archives/2020/12/_index.id.md b/content/archives/2020/12/_index.id.md new file mode 100644 index 0000000..c00f7ed --- /dev/null +++ b/content/archives/2020/12/_index.id.md @@ -0,0 +1,3 @@ +--- +title: Des +--- diff --git a/content/archives/2020/12/_index.md b/content/archives/2020/12/_index.md new file mode 100644 index 0000000..f92a4e5 --- /dev/null +++ b/content/archives/2020/12/_index.md @@ -0,0 +1,3 @@ +--- +title: Dec +--- diff --git a/content/archives/2020/_index.id.md b/content/archives/2020/_index.id.md new file mode 100644 index 0000000..8dad6eb --- /dev/null +++ b/content/archives/2020/_index.id.md @@ -0,0 +1,3 @@ +--- +title: 2020 +--- diff --git a/content/archives/2020/_index.md b/content/archives/2020/_index.md new file mode 100644 index 0000000..8dad6eb --- /dev/null +++ b/content/archives/2020/_index.md @@ -0,0 +1,3 @@ +--- +title: 2020 +--- diff --git a/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/dc-rake.png b/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/dc-rake.png new file mode 100644 index 0000000..63bf291 Binary files /dev/null and b/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/dc-rake.png differ diff --git a/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01.png b/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01.png new file mode 100644 index 0000000..df54d54 Binary files /dev/null and b/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01.png differ diff --git a/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/index.md b/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/index.md new file mode 100644 index 0000000..043b772 --- /dev/null +++ b/content/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/index.md @@ -0,0 +1,189 @@ +--- +title: "Discourse Rake Posts Snippets from BBCode to Markdown" +description: "After migrated devilzc0de from MyBB to Discourse, many things needs to be done. One of them is to rake and rebake the BBCode tags posts to Markdown." +date: 2020-06-14T12:55:12+07:00 +lastmod: +draft: false +noindex: false +featured: false +pinned: false +# comments: false +series: +# - +categories: + - SysAdmin +tags: + - Discourse + - Devilzc0de + - Ruby + - MyBB + - PostgreSQL +images: +# - +# menu: +# main: +# weight: 100 +# params: +# icon: +# vendor: bs +# name: book +# color: '#e24d0e' +authors: + - ditatompel +--- + +It's been more than 1 year since I [migrated devilzc0de from MyBB to Discourse]({{< ref "/blog/story-behind-the-all-new-devilzc0de-migration-process/index.md" >}}) and many things needs to be done after the migration process is complete. One of them is to `rake` (and `rebake`, if needed) the **BBCode** tags to **Markdown** for each posts. + + + +Before you start you need to: +- Backup your forum before perform any actions because you may break every single posts content and PMs. +- Prepare your time and resource, especially if your forum had lots of posts. +- Know that Discourse use PostgreSQL database which use [POSIX regex](https://www.postgresql.org/docs/9.3/functions-matching.html#FUNCTIONS-POSIX-REGEXP) to perform regex matching and it will be case-sensitive. +- Know that you can use BBCode plugin for Discourse like [discourse-bbcode](https://meta.discourse.org/t/discourse-bbcode/65425) without perform any of these actions. + +If you understand the risks (and you have another option) and still want to continue without additional plugins like I do, then go ahead. You need to enter your Discourse app by executing `./launcher enter app` from your root Discourse directory. + +## Remove Color, Size, Align, and Font Tags +Color, size, font and align tags may different in each post, like `[color=#ff3333]` or `[color=red]`, `[font=‘Open Sans’, sans-serif]`, `[align=center]`, etc. These rake post command will remove any general BBCode color, size, font, and align tags. + +![Discourse Rake](dc-rake.png#center) + +![Discourse Replace BBCode to Markdown](feature-dc-rake-01.png#center) + +### BBCode Color Tags +```ruby +rake posts:delete_word['\\[color.*?\\]|\\[\\/color\\]',regex] +``` + +### BBCode Size Tags +```ruby +rake posts:delete_word['\\[size.*?\\]|\\[\\/size\\]',regex] +``` +### BBCode Align Tags +```ruby +rake posts:delete_word['\\[align.*?\\]|\\[\\/align\\]',regex] +``` + +### BBCode Font Tags +```ruby +rake posts:delete_word['\\[font.*?\\]|\\[\\/font\\]',regex] +``` + +### All of Them Together +```ruby +rake posts:delete_word['\\[color.*?\\]|\\[\\/color\\]|\\[size.*?\\]|\\[\\/size\\]|\\[align.*?\\]|\\[\\/align\\]|\\[font.*?\\]|\\[\\/font\\]',regex] +``` + +> _**Note**: The regex is **case-sensitive**, tags with **uppercase** will not be removed. You need to check posts again by your self._ + +## Replace String or Words (Remap) +You can use `rake post:remap` to perform simple replacement. For example, oldest devilzc0de forum post is from 2010 where at that time, we rarely found sites using https. + +But now, https is everywhere and browser won't display mixed content. So, to replace `http://` to `https://` for each posts : +```ruby +rake posts:remap["http://","https://"] +``` + +This works for tagging user tags and emoji too. + +> _**Note**: You may increase `sidekiq` workers by updating Discourse `app.yml` `UNICORN_SIDEKIQS` **env** to spin up sidekiq queue for onebox and remote image fetch after remapping http to https._ + +Unfortunately, rake remap doesn't work for `[code]`, `[spoiler]`, `[php]`, and `[qoute]` tags. Here is the example : + +In old MyBB forum, user using `[code]` block following with the actual codes without new line will work. But, markdown code tags works if you use new line after ``` block. + +```plain +[code]var promise = new Promise(function(resolve, reject) { + // do a thing, possibly async, then… + + if (/* everything is fine */) { + resolve("Worked!"); + } + else { + reject(Error("Didn't work")); + } +}); +[/code] +``` + +`[code]` tags above will work on **MyBB** and produce: + +```javascript +var promise = new Promise(function(resolve, reject) { + // do a thing, possibly async, then… + + if (/* everything is fine */) { + resolve("Worked!"); + } + else { + reject(Error("Didn't work")); + } +}); +``` + +But on Discourse which use **Markdown**, if I replace `[code]` tags with ``` will produce : +
```var promise = new Promise(function(resolve, reject) {
+  // do a thing, possibly async, then…
+
+  if (/* everything is fine */) {
+    resolve("Worked!");
+  }
+  else {
+    reject(Error("Didn't work"));
+  }
+});
+```
+
+ +Code above **will not recognised as code block**. We need to add **new line** after first opening \``` block. Unfortunately (at least for me), using rake posts:remap["[code]","```\n"] doesn't work and only produce the **"\n"** as plain text. The only working solution for me is **directly update raw PG database**. + +## PostgreSQL Raw Update +You need to enter **PostgreSQL** on your Discourse app to run all PG query below. If you don't know how to do it, run `su -c 'psql discourse' postgres` after `./launcher enter app` command. + +> _**Note**: You need to `rebake` your post after update PostgreSQL post DB. To avoid rebake all your posts, you can use `rebake_match`. See example below._ + +### Replace Spoiler Tags With Details Tags +```sql +UPDATE posts set raw=replace(raw, '[spoiler]', '[details=Spoiler]'||chr(10)) where raw like '%[spoiler]%'; +UPDATE posts set raw=replace(raw, '[spoiler=', '[details=') where raw like '%[spoiler=%'; +UPDATE posts set raw=replace(raw, '[/spoiler]', chr(10)||'[/details]') where raw like '%[/spoiler]%'; +``` + +After updating database, exit from postgres user and run rebake post. +```ruby +rake posts:rebake_match["\[details"] +``` + +### Replace MyBB [php] Tags With Markdown PHP Syntax Highlight +```sql +UPDATE posts set raw=replace(raw, '[php]', '```php'||chr(10)) where raw like '%[php]%'; +UPDATE posts set raw=replace(raw, '[/php]', chr(10)||'```') where raw like '%[/php]%'; +``` + +After updating database, exit from postgres user and run rebake post. + +```ruby +rake posts:rebake_match["\`\`\`php"] +``` + +### Replace [code] tags With Markdown Tags +```sql +UPDATE posts set raw=replace(raw, '[code]', '```'||chr(10)) where raw like '%[code]%'; +UPDATE posts set raw=replace(raw, '[/code]', chr(10)||'```') where raw like '%[/code]%'; +``` + +After updating database, exit from postgres user and run rebake post. + +```ruby +rake posts:rebake_match["\`\`\`"] +``` + +## ToDo's +- `[ul]`, `[ol]` and `[li]` tags replace to Markdown list tags +- `[quote]` Tags to Markdown quote tags + +Please share if you have done mass replace for those two to do lists above. + +## Credits +- [Cameron:D](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729/70?u=ditatompel) and [Coin-coin le Canapin](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729/72?u=ditatompel) post. \ No newline at end of file diff --git a/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/dc-rake_hu0e94aa9862c69403badb08c7c45fdd43_146558_570x340_resize_q75_h2_box_3.webp b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/dc-rake_hu0e94aa9862c69403badb08c7c45fdd43_146558_570x340_resize_q75_h2_box_3.webp new file mode 100644 index 0000000..62f7e05 Binary files /dev/null and b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/dc-rake_hu0e94aa9862c69403badb08c7c45fdd43_146558_570x340_resize_q75_h2_box_3.webp differ diff --git a/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_0x360_resize_box_3.png b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_0x360_resize_box_3.png new file mode 100644 index 0000000..3ed2107 Binary files /dev/null and b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_0x360_resize_box_3.png differ diff --git a/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_0x640_resize_box_3.png b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_0x640_resize_box_3.png new file mode 100644 index 0000000..872aadd Binary files /dev/null and b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_0x640_resize_box_3.png differ diff --git a/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_1280x696_resize_q75_h2_box_3.webp b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_1280x696_resize_q75_h2_box_3.webp new file mode 100644 index 0000000..5deff8e Binary files /dev/null and b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_1280x696_resize_q75_h2_box_3.webp differ diff --git a/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_151926b3cbb4b558d4fffa2af02a3523.webp b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_151926b3cbb4b558d4fffa2af02a3523.webp new file mode 100644 index 0000000..d9a9caa Binary files /dev/null and b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_151926b3cbb4b558d4fffa2af02a3523.webp differ diff --git a/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_f80d64542274654b911d5c0f7e343993.webp b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_f80d64542274654b911d5c0f7e343993.webp new file mode 100644 index 0000000..08af743 Binary files /dev/null and b/resources/_gen/images/blog/discourse-rake-posts-snippets-from-bbcode-to-markdown/feature-dc-rake-01_hu196870e331b5feb0f972443886ff0f7f_78841_f80d64542274654b911d5c0f7e343993.webp differ