{"id":3163,"date":"2016-02-16T03:25:39","date_gmt":"2016-02-16T03:25:39","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3163"},"modified":"2016-02-16T03:25:39","modified_gmt":"2016-02-16T03:25:39","slug":"scaladoc-markdown-jekyll","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/scaladoc-markdown-jekyll\/","title":{"rendered":"Convert scaladoc output to Markdown and Jekyll"},"content":{"rendered":"<p>Scaladoc generates a listing page for every class you run it on.<\/p>\n<p>In this post, I&#8217;ll show how to convert the output of the entire API documentation (on the official scala site) to Markdown that is compatible with Jekyll (so that you can add \/ modify formatting as desired).<\/p>\n<p>I got the main scala library, forked it, and built from source. To do this, you will need some pre-requisites:<\/p>\n<pre lang=\"bash\">\nbrew update\nbrew install ant\nbrew install gem\ngem install jekyll\n<\/pre>\n<p>There is an ant target that lets you generate all of the scala documentation from source (this is what you&#8217;d need if you want to keep up with the nightly builds).<\/p>\n<pre lang=\"bash\">\ngit clone https:\/\/github.com\/garysieling\/scala.git\ncd scala\nant docs\n<\/pre>\n<p>This took ~40 minutes for me.<\/p>\n<p>To convert this to markdown, there is a handy library called <a href=\"https:\/\/github.com\/todesking\/nyandoc\n\">&#8220;nyandoc&#8221;<\/a>, but you need to install a scala dependency tracking thing called <a href=\"https:\/\/github.com\/n8han\/conscript\">&#8220;conscript&#8221;<\/a> first (this seems to be a wrapper around SBT).<\/p>\n<p>There are a couple ways to do this, and I had to fiddle with it to get it to work.<\/p>\n<p>You can either download the JAR and install or yolo it and get code directly from Github:<\/p>\n<pre>\ncurl https:\/\/raw.githubusercontent.com\/n8han\/conscript\/master\/setup.sh | sh\n<\/pre>\n<p>I had problems with both methods, but eventually got this to work.<\/p>\n<p>Once conscript installs it&#8217;s not on your path by default, but it&#8217;s not a big deal. You then install nyandoc with this command:<\/p>\n<pre lang=\"bash\">\n\/Users\/gary\/bin\/cs todesking\/nyandoc\nsbt launcher version 0.13.7\n\nConscripted todesking\/nyandoc to \/Users\/gary\/bin\/nyandoc\n<\/pre>\n<p>This tool is also not on your path.<\/p>\n<p>To convert to markdown, go into the folder where you build scala, and there will be a &#8220;library&#8221; folder that has the compiled scaladoc output.<\/p>\n<pre lang=\"bash\">\ncd scala\/build\/scaladoc\n\/Users\/gary\/bin\/nyandoc library library-markdown\n<\/pre>\n<p>The above command should only take a few minutes.<\/p>\n<p>Now, copy the output over to your jekyll site. <\/p>\n<pre lang=\"bash\">\ncp -R library-markdown ..\/..\/..\/scaladoc-jekyll\/_posts\/\ncd ..\/..\/..\/scala-jekyll\/_posts\n<\/pre>\n<p>Scaladoc output is a deeply nested folder structure. For this example the easiest thing to do is to flatten this:<\/p>\n<pre lang=\"bash\">\nfind *\/ -type f -exec bash -c 'file=${1#.\/}; echo mv \"$file\" \"${file\/\/\\\/\/_}\"' _ '{}' \\; > move_all.sh\nchmod +x .\/move_all.sh \nmv *.md ..\n<\/pre>\n<p>You still have a problem, because Jekyll expects a blog, with numbered blog posts.<\/p>\n<p>So, we can cheat the system by adding this:<\/p>\n<pre lang=\"bash\">\nls | sed \"s\/\\(.*\\)\/mv \\1 2016-02-15-\\1\/\" > move_all.sh\nchmod +x move_all.sh \n.\/move_all.sh\n<\/pre>\n<p>Now, you will have a Jekyll site with all the scala docs (one page per article).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scaladoc generates a listing page for every class you run it on. In this post, I&#8217;ll show how to convert the output of the entire API documentation (on the official scala site) to Markdown that is compatible with Jekyll (so that you can add \/ modify formatting as desired). I got the main scala library, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/scaladoc-markdown-jekyll\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Convert scaladoc output to Markdown and Jekyll&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[22],"tags":[480,486],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3163"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3163"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3163\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}