-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scaladoc feature for preprocessing markdown files and publishing …
…docs.scala-lang
- Loading branch information
1 parent
3109226
commit 8ec44e0
Showing
12 changed files
with
312 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
shopt -s extglob # needed for rm everything but x | ||
echo "Working directory: $PWD" | ||
|
||
GENDOC_EXTRA_ARGS=$@ | ||
GIT_HEAD=$(git rev-parse HEAD) # save current head for commit message in gh-pages | ||
PREVIOUS_SNAPSHOTS_DIR="$PWD/../prev_snapshots" | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)" | ||
SITE_OUT_DIR="$PWD/docs/_site" | ||
|
||
DOCS_SCALA_LANG_DIR="$PWD/docsScalaLang" | ||
|
||
rm -rf $DOCS_SCALA_LANG_DIR | ||
mkdir -pv $DOCS_SCALA_LANG_DIR | ||
git clone "https://github.com/scala/docs.scala-lang.git" $DOCS_SCALA_LANG_DIR | ||
|
||
SBT="$SCRIPT_DIR/sbt" | ||
mkdir -pv $SITE_OUT_DIR | ||
env "scaladoc.projectFormat=md" "$SBT" "scaladoc/copyTheScaladocJsOutput $DOCS_SCALA_LANG_DIR/scripts/searchbar.js" | ||
"dist/target/pack/bin/scaladoc" "-d" "$SITE_OUT_DIR" "-format" "md" "-siteroot" "docs" "/dev/null" | ||
|
||
if [ ! -d "$SITE_OUT_DIR" ]; then | ||
echo "Output directory did not exist: $SITE_OUT_DIR" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
cp -rf "$SITE_OUT_DIR/docs/reference"/* "$DOCS_SCALA_LANG_DIR/_scala3-reference" | ||
cp -f "$SITE_OUT_DIR/resources/my.css" "$DOCS_SCALA_LANG_DIR/scripts/my.css" | ||
cp -f "$SITE_OUT_DIR/resources/footer.html" "$DOCS_SCALA_LANG_DIR/_includes/footer.html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
package dotty.tools.scaladoc | ||
|
||
object Main extends App { | ||
Searchbar() | ||
SocialLinks() | ||
CodeSnippets() | ||
DropdownHandler() | ||
Ux() | ||
} | ||
object Main: | ||
|
||
private def common(): Unit = | ||
CodeSnippets() | ||
|
||
def main(): Unit = | ||
Searchbar() | ||
SocialLinks() | ||
DropdownHandler() | ||
Ux() | ||
common() | ||
|
||
/** | ||
* This main is conditionally enabled by system env variable `scaladoc.projectFormat=md` | ||
* passed in ./projects/scripts/genDocsScalaLang | ||
* The reason why we have to pass the condition by env variable is because js is build before scaladoc, | ||
* so we cannot access its args | ||
*/ | ||
def markdownMain(): Unit = | ||
common() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
scaladoc/src/dotty/tools/scaladoc/renderers/MarkdownRenderer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package dotty.tools.scaladoc | ||
package renderers | ||
|
||
import util.HTML._ | ||
import collection.JavaConverters._ | ||
import java.net.URI | ||
import java.net.URL | ||
import dotty.tools.scaladoc.site._ | ||
import scala.util.Try | ||
import org.jsoup.Jsoup | ||
import java.nio.file.Paths | ||
import java.nio.file.Path | ||
import java.nio.file.Files | ||
import java.nio.file.FileVisitOption | ||
import java.io.File | ||
|
||
class MarkdownRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: DocContext) | ||
extends Renderer(rootPackage, members, extension = "md"): | ||
|
||
override def render(): Unit = | ||
renderResources() | ||
super.render() | ||
|
||
override def pageContent(page: Page, parents: Vector[Link]): AppliedTag = | ||
renderContent(page) | ||
|
||
private def renderResources(): Seq[String] = | ||
|
||
// TODO REMOVE THIS CODE AND RESOURCES UNDER docs/resources | ||
// when we sort out the css classes | ||
def siteRoot = staticSite.get.root.toPath | ||
def pathToResource(p: String) = Resource.File(p, siteRoot.resolve(p)) | ||
|
||
def harvestResources(path: String) = | ||
val siteImgPath = siteRoot.resolve(path) | ||
if !Files.exists(siteImgPath) then Nil | ||
else | ||
val allPaths = Files.walk(siteImgPath, FileVisitOption.FOLLOW_LINKS) | ||
val files = allPaths.filter(Files.isRegularFile(_)).iterator().asScala | ||
files.map(p => siteRoot.relativize(p).toString).toList | ||
|
||
val staticResources = staticSite.toSeq.flatMap { _ => | ||
harvestResources("images") ++ harvestResources("resources") | ||
} | ||
staticResources.map(pathToResource).flatMap(renderResource) | ||
// END TODO REMOVE THIS CODE AND RESOURCES UNDER docs/resources | ||
|
||
allResources(Nil).flatMap(renderResource) |
Oops, something went wrong.