Skip to content

Commit

Permalink
Update docs script to latest stable Ammonite (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab authored Mar 16, 2023
1 parent e984e6a commit 69abbc9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ jobs:
java-version: 8
- name: Generate Website
run: |
set -eux
curl -L -o ~/amm https://github.com/com-lihaoyi/Ammonite/releases/download/2.5.4/2.13-2.5.4 && chmod +x ~/amm
cd docs
~/amm build.sc
./amm build.sc
- name: Deploy Website
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
12 changes: 5 additions & 7 deletions ci/version.sc
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import ammonite.ops.{%%, pwd}

val isMasterCommit = {
sys.env.get("TRAVIS_PULL_REQUEST").contains("false") &&
(sys.env.get("TRAVIS_BRANCH").contains("master") || sys.env("TRAVIS_TAG") != "")
}

def gitHead =
sys.env.get("TRAVIS_COMMIT").getOrElse(
%%('git, "rev-parse", "HEAD")(pwd).out.string.trim()
os.proc("git", "rev-parse", "HEAD").call().out.string.trim()
)



def publishVersion = {
val tag =
try Option(
%%('git, 'describe, "--exact-match", "--tags", "--always", gitHead)(pwd).out.string.trim()
os.proc("git", "describe", "--exact-match", "--tags", "--always", gitHead).call().out.string.trim()
)
catch{case e => None}

val dirtySuffix = %%('git, 'diff)(pwd).out.string.trim() match{
val dirtySuffix = os.proc("git", "diff").call().out.string.trim() match{
case "" => ""
case s => "-DIRTY" + Integer.toHexString(s.hashCode)
}

tag match{
case Some(t) => (t, t)
case None =>
val latestTaggedVersion = %%('git, 'describe, "--abbrev=0", "--always", "--tags")(pwd).out.trim
val latestTaggedVersion = os.proc("git", "describe", "--abbrev=0", "--always", "--tags").call().out.trim

val commitsSinceLastTag =
%%('git, "rev-list", gitHead, "--not", latestTaggedVersion, "--count")(pwd).out.trim.toInt
os.proc("git", "rev-list", gitHead, "--not", latestTaggedVersion, "--count").call().out.trim.toInt

(latestTaggedVersion, s"$latestTaggedVersion-$commitsSinceLastTag-${gitHead.take(6)}$dirtySuffix")
}
Expand Down
31 changes: 31 additions & 0 deletions docs/amm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env sh

# This is a wrapper script, that automatically download ammonite from GitHub release pages
# You can give the required ammonite version with AMM_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_AMM_VERSION
DEFAULT_AMM_VERSION=2.5.8
SCALA_VERSION=2.13
set -e

if [ -z "$AMM_VERSION" ] ; then
AMM_VERSION=$DEFAULT_AMM_VERSION
fi

AMM_DOWNLOAD_PATH="$HOME/.ammonite/download"
AMM_EXEC_PATH="${AMM_DOWNLOAD_PATH}/${AMM_VERSION}_$SCALA_VERSION"

if [ ! -x "$AMM_EXEC_PATH" ] ; then
mkdir -p $AMM_DOWNLOAD_PATH
DOWNLOAD_FILE=$AMM_EXEC_PATH-tmp-download
AMM_DOWNLOAD_URL="https://github.com/lihaoyi/ammonite/releases/download/${AMM_VERSION%%-*}/$SCALA_VERSION-$AMM_VERSION"
curl --fail -L -o "$DOWNLOAD_FILE" "$AMM_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
mv "$DOWNLOAD_FILE" "$AMM_EXEC_PATH"
unset DOWNLOAD_FILE
unset AMM_DOWNLOAD_URL
fi

unset AMM_DOWNLOAD_PATH
unset AMM_VERSION

exec $AMM_EXEC_PATH "$@"
30 changes: 14 additions & 16 deletions docs/build.sc
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// Load dependencies
import $ivy.{`org.pegdown:pegdown:1.6.0`, `com.lihaoyi::scalatags:0.6.5`}
import $ivy.{`org.pegdown:pegdown:1.6.0`, `com.lihaoyi::scalatags:0.9.4`}
import $file.pageStyles, pageStyles._
import $file.pages, pages._
import scalatags.Text.all._
import $file.^.ci.version
import ammonite.ops._
import collection.JavaConverters._
import org.pegdown.{PegDownProcessor, ToHtmlSerializer, LinkRenderer, Extensions}
import org.pegdown.ast.{VerbatimNode, ExpImageNode, HeaderNode, TextNode, SimpleNode, TableNode}

val (releaseTag, label) = version.publishVersion

val postsFolder = cwd/'pages
val postsFolder = os.pwd/'pages

interp.watch(postsFolder)

val targetFolder = cwd/'target
val targetFolder = os.pwd/'target


val (markdownFiles, otherFiles) = ls! postsFolder partition (_.ext == "md")
val (markdownFiles, otherFiles) = os.list(postsFolder).partition (_.ext == "md")
markdownFiles.foreach(println)
// Walk the posts/ folder and parse out the name, full- and first-paragraph-
// HTML of each post to be used on their respective pages and on the index
Expand All @@ -35,10 +34,10 @@ val posts = {

val txt =
"""\$\$\$([a-zA-Z_0-9]+)""".r.replaceAllIn(
read(path),
os.read(path),
m => {
val g = m.group(1)
val txt = read(ls(pwd/up/'example/g/'app/'src).head).replace("$", "\\$")
val txt = os.read(os.list(os.pwd/os.up/"example"/g/"app"/"src").head).replace("$", "\\$")
val downloadLink =
s"https://github.com/lihaoyi/cask/releases/download/$releaseTag/$g-$releaseTag.zip"

Expand All @@ -61,8 +60,7 @@ val posts = {
if(!rendering.text.equals("")){
printAttribute("alt", rendering.text)
}
import collection.JavaConversions._
for (attr <- rendering.attributes) {
for (attr <- rendering.attributes.asScala) {
printAttribute(attr.name, attr.value)
}
printer.print(" style=\"max-width: 100%; max-height: 500px\"")
Expand Down Expand Up @@ -141,7 +139,7 @@ val posts = {
).render

val rawHtmlContent = new Serializer().toHtml(ast) + postlude
PostInfo(name, headers, rawHtmlContent)
PostInfo(name, headers.toSeq, rawHtmlContent)
}
}

Expand All @@ -155,15 +153,15 @@ def formatRssDate(date: java.time.LocalDate) = {
@main
def main(publish: Boolean = false) = {

rm! targetFolder
os.remove.all(targetFolder)

mkdir! targetFolder/'page
os.makeDir.all(targetFolder/"page")
for(otherFile <- otherFiles){
cp(otherFile, targetFolder/'page/(otherFile relativeTo postsFolder))
os.copy(otherFile, targetFolder/'page/(otherFile relativeTo postsFolder))
}

cp(pwd/"favicon.png", targetFolder/"favicon.ico")
cp(pwd/"logo-white.svg", targetFolder/"logo-white.svg")
os.copy(os.pwd/"favicon.png", targetFolder/"favicon.ico")
os.copy(os.pwd/"logo-white.svg", targetFolder/"logo-white.svg")

for(i <- posts.indices){
val post = posts(i)
Expand All @@ -187,7 +185,7 @@ def main(publish: Boolean = false) = {
)


write(
os.write(
if (i == 0) targetFolder / "index.html"
else targetFolder/'page/s"${sanitize(post.name)}.html",
postContent(
Expand Down

0 comments on commit 69abbc9

Please sign in to comment.