/scalate-website/src/documentation/siteGen.page

http://github.com/scalate/scalate · Visualforce Page · 230 lines · 163 code · 67 blank · 0 comment · 0 complexity · d7f437e650a16900c5b129228e0a5d34 MD5 · raw file

  1. ---
  2. title: Site Generator
  3. in_menu: false
  4. sort_info: 2
  5. --- name:overview
  6. # Site Generator
  7. Create that static website with Scalate
  8. --- name:content pipeline:jade
  9. .left
  10. :markdown
  11. # Overview
  12. .right
  13. :markdown
  14. Scalate can be used to create a static website reusing all of the various
  15. Scalate template languages, filters, wiki markups and pipelines.
  16. .left
  17. :markdown
  18. # Creating a Site
  19. .right
  20. :markdown
  21. The quickest way to get started is to [install the Scalate Tool](installing.html) then run
  22. scalate create sitegen mygroup myartifactid
  23. This creates an example sitegen project in the myartifactid directory.
  24. Inside the project run the following
  25. mvn jetty:run
  26. Then open [http://localhost:8080/](http://localhost:8080/) and you should see the styled website.
  27. The source for the site in wiki markup or templates are all in the `src` directory.
  28. However you can also use the [Console](console.html) to edit the templates directly.
  29. Just open the console via the top right icon. You will then see links to the page you are
  30. looking at along with the layout template used to render the current page. Clicking on the link
  31. will open the wiki page or template in your editor. Refer to the [Console](console.html) for
  32. details of changing your default editor.
  33. When you change a file and hit save you can hit reload in your browser to see the newly
  34. rendered page. Whether you change a wiki page, an include or a template you will always see the
  35. most up to date page in your browser.
  36. .left
  37. :markdown
  38. # Generating the static site
  39. .right
  40. :markdown
  41. ### Maven
  42. To generate the static site run
  43. mvn install
  44. This will invoke the **scalate:sitegen** plugin which generates the static website to the
  45. **target/sitegen** directory.
  46. There's also a **scalate:sitegen-no-fork** plugin goal available that can be used to configure
  47. additional/different executions of the goal in an existing build.
  48. ### sbt
  49. To create a sitegen project in sbt, first add the plugin dependency to
  50. `project/plugins/Plugins.scala`:
  51. {pygmentize:: scala}
  52. lazy val scalate_plugin = "org.fusesource.scalate" % "sbt-scalate-plugin_${scala_compat_tag}" % "${project_version}"
  53. {pygmentize}
  54. Then mix the `org.fusesource.scalate.sbt.SiteGenWebProject` into your
  55. web project, along with the Scalate dependencies. For example:
  56. {pygmentize:: scala}
  57. import org.scalate.fusesource.sbt.SiteGenWebProject
  58. class MySiteGenProject(info: ProjectInfo) extends
  59. DefaultWebProject(info) with
  60. SiteGenWebProject {
  61. lazy val scalate_core = "org.fusesource.scalate" % "scalate-core_${scala_compat_tag}" % "${project_version}"
  62. lazy val servlet = "javax.servlet" % "servlet-api"% "2.5"
  63. lazy val logback = "ch.qos.logback" % "logback-classic" % "0.9.26"
  64. }
  65. {pygmentize}
  66. This creates a ***generate-site*** action, which is run as a dependency of
  67. the ***package*** action. The static web site is generated to the
  68. ***target/sitegen*** directory.
  69. .left
  70. :markdown
  71. <h1 id="deploy">Deploying the static site</h1>
  72. .right
  73. :markdown
  74. Before you start trying to deploy you need to add a `distributionManagement` section
  75. to your pom.xml. For example projects hosted on the
  76. [FuseForge](http://fusesource.com/forge/) tend to use something like this
  77. {pygmentize:: xml}
  78. <distributionManagement>
  79. <site>
  80. <id>website.fusesource.org</id>
  81. <name>website</name>
  82. <url>dav:http://fusesource.com/forge/dav/myproject</url>
  83. </site>
  84. </distributionManagement>
  85. {pygmentize}
  86. Any of the Maven Wagon transport mechanisms should be supported (file, scp, dav etc).
  87. Then to actually deploy the static site to some remote system you can use the following:
  88. mvn scalate:deploy
  89. This will deploy the site generated by the `scalate:sitegen` goal to the website
  90. location you have provided in the `site` area of the `distributionManagement` section of
  91. your `pom.xml`
  92. If you also want to deploy a regular maven website too then you can reuse the same
  93. site configuration as above but just specify a `remoteDirectory` property on the
  94. plugin (which defaults to ".." to avoid including the maven project name in the deploy url)
  95. You will need to add the project's Web server to your Maven configuration:
  96. {pygmentize:: xml}
  97. <server>
  98. <id>website.fusesource.org</id>
  99. <username>xxxx</username>
  100. <password>xxxxx</password>
  101. </server>
  102. {pygmentize}
  103. .left
  104. :markdown
  105. <h1 id="linkCheck">Link Checking</h1>
  106. .right
  107. :markdown
  108. Its easy to make a mistake in your wiki files and create a bad link. So we have a
  109. linkcheck report you can add to your pom.xml if you want to generate a report of any bad
  110. links that are created as part of your statically generated HTML.
  111. Just add the following to your `pom.xml` and you'll get a nice LinkCheck report.
  112. {pygmentize:: xml}
  113. <reporting>
  114. <plugins>
  115. <plugin>
  116. <groupId>org.fusesource.scalate</groupId>
  117. <artifactId>maven-scalate-plugin_#{scala_compat_tag}</artifactId>
  118. <version>${project_version}</version>
  119. </plugin>
  120. </plugins>
  121. </reporting>
  122. {pygmentize}
  123. .left
  124. :markdown
  125. <h1 id="livereload">Using LiveReload</h1>
  126. .right
  127. :markdown
  128. [LiveReload](http://github.com/mockko/livereload) is a tool and a browser plugin for Safari and Chrome.
  129. runlivereload
  130. LiveReload watches the files on your machine so that as you change a template, CSS or JavaScript
  131. file it will force a reload in the web browser. This means you can sit in your editor changing
  132. files and have a browser window open and you don't have to keep changing focus between the editor
  133. and browser and hitting reload in the browser. You can just hit save in your editor and see the
  134. results in your browser.
  135. Or you can use the livereload script directly...
  136. livereload src
  137. This works thanks to the `src/.livereload` configuration file knowing about the scalate
  138. template files.
  139. .left
  140. :markdown
  141. <h1 id="export">Exporting Confluence Wikis</h1>
  142. .right
  143. :markdown
  144. If you have a legacy site you want to port over from Confluence you can run the following command.
  145. For example if your Confluence space is called FOO at Apache then the following command will
  146. dump its content as wiki text files...
  147. scalate confexport --user user --password pass \
  148. https://cwiki.apache.org/confluence/rpc/xmlrpc FOO ./out
  149. .left
  150. :markdown
  151. <h1 id="bootstrapping">Bootstrapping</h1>
  152. .right
  153. :markdown
  154. When generating static sites you often need a little bit of bootstrap code
  155. to configure things such that you can configure some filters (for example
  156. the `{snippet}` macros inside Confluence wiki files) which are then setup
  157. and used whether you run Scalate using `mvn jetty:run` for the live website
  158. or use `mvn scalate:sitegen` to generate the static site.
  159. Thankfully there's a really simple way to add in any custom initialisation
  160. code in Scalate. Just add a class called `scalate.Boot` which should be a
  161. class with a method called `run()` which can then do whatever you need to
  162. configure things before the template engine starts to render your templates
  163. and wiki files.