From 7f2bd2cc4b9ca138afb805a8d01b8d1e28be288d Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 2 Jun 2014 12:54:01 -0400 Subject: [PATCH] Remove nested site generation in favor of just creating Scaladoc/Sxr docs. * Do not delete versioned docs from sbt/website project * Just sync api/sxr directories * Remove all build-related information for old sphinx docs. Replaces #1385 --- project/Docs.scala | 167 ++------------------------------------------- 1 file changed, 5 insertions(+), 162 deletions(-) diff --git a/project/Docs.scala b/project/Docs.scala index f417038eb..999b46c1c 100644 --- a/project/Docs.scala +++ b/project/Docs.scala @@ -12,44 +12,19 @@ object Docs { - val rootFiles = SettingKey[Seq[File]]("root-files", "Location of file that will be copied to the website root.") - val latestRelease = SettingKey[Boolean]("latest-release") - val siteExcludes = Set(".buildinfo", "objects.inv") def siteInclude(f: File) = !siteExcludes.contains(f.getName) - def siteSourceBase(siteSourceVersion: String) = s"https://github.com/sbt/sbt/raw/$siteSourceVersion/src/sphinx/" - val sbtSiteBase = uri("http://www.scala-sbt.org/") - - val SnapshotPath = "snapshot" - val ReleasePath = "release" - val DocsPath = "docs" - val IndexHtml = "index.html" - val HomeHtml = "home.html" - val VersionPattern = """(\d+)\.(\d+)\.(\d+)(-.+)?""".r.pattern def settings: Seq[Setting[_]] = site.settings ++ - site.sphinxSupport(DocsPath) ++ site.includeScaladoc("api") ++ siteIncludeSxr("sxr") ++ - ghPagesSettings ++ - Seq( - SphinxSupport.sphinxEnv in SphinxSupport.Sphinx <<= sphinxEnvironmentVariables, - SphinxSupport.sphinxIncremental in SphinxSupport.Sphinx := true, - // TODO: set to true with newer sphinx plugin release - SphinxSupport.enableOutput in SphinxSupport.generatePdf := false - ) + ghPagesSettings def ghPagesSettings = ghpages.settings ++ Seq( git.remoteRepo := "git@github.com:sbt/sbt.github.com.git", localRepoDirectory, ghkeys.synchLocal <<= synchLocalImpl, - rootFiles := { - val base = (sourceDirectory in SphinxSupport.Sphinx).value - Seq("CNAME", "robots.txt").map(base / _) - }, - latestRelease in ThisBuild := false, - commands += setLatestRelease, GitKeys.gitBranch in ghkeys.updatedRepository := Some("master") ) @@ -66,146 +41,14 @@ object Docs site.addMappingsToSiteDir(mappings in sxr, prefix) ) - def sphinxEnvironmentVariables = (scalaVersion, version, isSnapshot) map { (scalaV, sbtV, snap) => - // sphinx's terminology: major.minor - def release(v: String): String = CrossVersion.partialVersion(v) match { - case Some((major,minor)) => major + "." + minor - case None => v - } - val siteVersion = sbtV.takeWhile(_ != '-') - val siteSourceVersion = if(snap) release(siteVersion) else siteVersion - Map[String,String]( - "sbt.full.version" -> sbtV, - "sbt.partial.version" -> release(sbtV), - "sbt.site.version" -> siteVersion, - "sbt.site.source.base" -> siteSourceBase(siteSourceVersion), - "sbt.binary.version" -> CrossVersion.binarySbtVersion(sbtV), - "scala.full.version" -> scalaV, - "scala.partial.version" -> release(scalaV), - "scala.binary.version" -> CrossVersion.binaryScalaVersion(scalaV) - ) - } - - def synchLocalImpl = (ghkeys.privateMappings, ghkeys.updatedRepository, version, isSnapshot, latestRelease, streams, rootFiles) map { - (mappings, repo, v, snap, latest, s, roots) => + def synchLocalImpl = (ghkeys.privateMappings, ghkeys.updatedRepository, version, streams) map { + (mappings, repo, v, s) => val versioned = repo / v - IO.delete(versioned) + IO.delete(versioned / "sxr") + IO.delete(versioned / "api") val toCopy = for( (file, target) <- mappings if siteInclude(file) ) yield (file, versioned / target) IO.copy(toCopy) - for(f <- roots) - IO.copyFile(f, repo / f.getName) - IO.touch(repo / ".nojekyll") - IO.write(repo / "versions.js", versionsJs(sortVersions(collectVersions(repo)))) - if(!snap && latest) - RootIndex(versioned / DocsPath / "home.html", repo / IndexHtml) - if(snap || latest) - linkSite(repo, v, if(snap) SnapshotPath else ReleasePath, s.log) - s.log.info("Copied site to " + versioned) - - if(latest) { - val (index, siteMaps) = SiteMap.generate(repo, sbtSiteBase, gzip=true, siteEntry(v), s.log) - s.log.info(s"Generated site map index: $index") - s.log.debug(s"Generated site maps: ${siteMaps.mkString("\n\t", "\n\t", "")}") - } - repo } - def siteEntry(CurrentVersion: String)(file: File, relPath: String): Option[Entry] = - { - val apiOrSxr = """([^/]+)/(api|sxr)/.*""".r - val docs = """([^/]+)/docs/.*""".r - val old077 = """0\.7\.7/.*""".r - val manualRedirects = """[^/]+\.html""".r - val snapshot = """(.+-SNAPSHOT|snapshot)/.+/.*""".r - // highest priority is the home page - // X/docs/ are higher priority than X/(api|sxr)/ - // release/ is slighty higher priority than / - // non-current releases are low priority - // 0.7.7 documentation is very low priority - // snapshots docs are very low priority - // the manual redirects from the old version of the site have no priority at all - relPath match { - case "index.html" => Some(Entry("weekly", 1.0)) - case docs(ReleasePath) => Some( Entry("weekly", 0.9) ) - case docs(CurrentVersion) => Some( Entry("weekly", 0.8) ) - case apiOrSxr(ReleasePath, _) => Some( Entry("weekly", 0.6) ) - case apiOrSxr(CurrentVersion, _) => Some( Entry("weekly", 0.5) ) - case snapshot(_) => Some( Entry("weekly", 0.02) ) - case old077() => Some( Entry("never", 0.01) ) - case docs(_) => Some( Entry("never", 0.2) ) - case apiOrSxr(_, _) => Some( Entry("never", 0.1) ) - case x => Some( Entry("never", 0.0) ) - } - } - def versionsJs(vs: Seq[String]): String = "var availableDocumentationVersions = " + vs.mkString("['", "', '", "']") - // names of all directories that are explicit versions - def collectVersions(base: File): Seq[String] = (base * versionFilter).get.map(_.getName) - def sortVersions(vs: Seq[String]): Seq[String] = vs.sortBy(versionComponents).reverse - def versionComponents(v: String): Option[(Int,Int,Int,Option[String])] = { - val m = VersionPattern.matcher(v) - if(m.matches()) - Some( (m.group(1).toInt, m.group(2).toInt, m.group(3).toInt, Option(m.group(4))) ) - else - None - } - def versionFilter = new PatternFilter(VersionPattern) && DirectoryFilter - - def linkSite(base: File, to: String, from: String, log: Logger) { - val current = base / to - assert(current.isDirectory, "Versioned site not present at " + current.getAbsolutePath) - val symlinkDir = base / from - symlinkDir.delete() - symlink(path = to, file = symlinkDir, log = log) - } - - // TODO: platform independence/use symlink from Java 7 - def symlink(path: String, file: File, log: Logger): Unit = - "ln" :: "-s" :: path :: file.getAbsolutePath :: Nil ! log match { - case 0 => () - case code => error("Could not create symbolic link '" + file.getAbsolutePath + "' with path " + path) - } - - def setLatestRelease = Command.command("latest-release-docs") { state => - Project.extract(state).append((latestRelease in ThisBuild := true) :: Nil, state) - } - -} -object RootIndex -{ - import Docs._ - import org.jsoup._ - - def apply(versionIndex: File, to: File) - { - val doc = Jsoup.parse(versionIndex, "UTF-8") - rewriteLinks(doc) - removeSearch(doc) - IO.write(to, doc.outerHtml) - } - def retargetIndexLink(original: String): String = - if(isAbsolute(original) || original.startsWith("#")) - original - else - ReleasePath + "/docs/" + original - - def isAbsolute(s: String): Boolean = (new java.net.URI(s)).isAbsolute - - def rewriteLinks(doc: nodes.Document) - { - rewriteLinks(doc, "*", "href") - rewriteLinks(doc, "script", "src") - } - def rewriteLinks(doc: nodes.Document, elemName: String, attrName: String): Unit = - for(elem <- select(doc, elemName + "[" + attrName + "]")) - elem.attr(attrName, retargetIndexLink(elem.attr(attrName))) - - def removeSearch(doc: nodes.Document): Unit = - doc.select(".search").remove() - - def select(doc: nodes.Document, s: String) = - { - import collection.JavaConverters._ - doc.select(s).iterator.asScala - } } \ No newline at end of file