How to create page contents from Groovy script?

Hi,

I am in the process of creating a Groovy script to import a Github wiki into XWiki. What I have done so far:

  • Cloned the Github wiki (which is an ordinary Git repo with Markdown documents);
  • Opened the _Sidebar.md file from that wiki, because that contains the table of contents;
  • Extracted all Markdown links from that TOC and found each corresponding .md file.

Now I want to create a wiki page for eacht .md file I found. I have browsed the API docs and found things like createDocumentReference. I also found some examples that use createDocumentReference. All examples I found do a redirect after that, but I don’t want that, I want to create the pages “in the background”.

I have a couple of questions:

  1. Should I use createDocumentReference or createPageReference? What’s the difference?
  2. If I call just createDocumentReference from Groovy, nothing seems to happen. I suppose I have to take some additional action to actually save/create the page?
  3. How do I add the contents to a page I created this way, from Groovy?
  4. How do I set the rendering engine to ‘Markdown’ for each created page?

I hope someone can help me with this step. Thanks in advance!

Best regards,
Bart Kummel

See for example https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/APIGuide/#HCreateanewDocument to create a new page programmatically.

You should use the Converter component and convert from MD to XWiki Syntax 2.1 for example.

See https://extensions.xwiki.org/xwiki/bin/view/Extension/Rendering%20Module/#HRenderingScriptService and especially the conversion example there at the bottom.

Note: you’ll need to enable MD in your wiki first. See https://extensions.xwiki.org/xwiki/bin/view/Extension/Rendering%20Administration%20Application/

Thanks, @vmassol, these are very helpful pointers. I was clearly searching in the wrong direction… :wink:

Thanks to the pointers from @vmassol I was able to create a script to import Github wikis into XWiki: https://snippets.xwiki.org/xwiki/bin/view/Extension/Github%20wiki%20import/

Well done, I’m impressed that you were able to find all of that by yourself, very cool :slight_smile: Now you’re becoming an XWiki developers! :slight_smile:

Thanks!

@bartkummel Would be great if you could open jira issue on the markdown project if you’ve found some issues/limitations (I see you’re doing some massaging in several places -I don’t know if that’s normal or if it’s to cover up for some bugs or limitations).

Thanks for the kind words, @vmassol. It was already my plan to open some issues in the Markdown project.

Thanks!