From 4babac06420b56f150ef1ee468bd998a607fc37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Zyba=C5=82a?= Date: Wed, 9 Mar 2022 16:05:37 +0100 Subject: [PATCH 1/3] Add table of contents to section indexes. Hide version dropdown in reference documentation. --- docs/_docs/contributing/index.md | 4 ++++ docs/_docs/index.md | 8 ++------ docs/_docs/internals/index.md | 5 +++++ .../changed-features/changed-features.md | 2 +- docs/_docs/reference/contextual/contextual.md | 2 +- .../dropped-features/dropped-features.md | 2 +- docs/_docs/reference/enums/enums-index.md | 2 +- .../reference/experimental/named-typeargs.md | 2 +- docs/_docs/reference/experimental/overview.md | 3 ++- .../language-versions/language-versions.md | 2 +- .../reference/metaprogramming/metaprogramming.md | 2 +- docs/_docs/reference/new-types/new-types.md | 2 +- .../other-new-features/other-new-types.md | 2 +- docs/_docs/reference/overview.md | 3 ++- docs/_docs/usage/index.md | 4 ++++ docs/_docs/usage/scaladoc/index.md | 2 +- docs/_layouts/index.html | 15 +++++++++++++-- docs/sidebar.yml | 7 +++++-- project/Build.scala | 1 + .../resources/referenceReplacements/sidebar.yml | 5 ++--- scaladoc-testcases/docs/_docs/docs/f1.md | 4 ++-- .../tools/scaladoc/site/LoadedTemplate.scala | 2 +- .../tools/scaladoc/site/StaticSiteContext.scala | 8 +++++--- 23 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 docs/_docs/contributing/index.md create mode 100644 docs/_docs/internals/index.md create mode 100644 docs/_docs/usage/index.md diff --git a/docs/_docs/contributing/index.md b/docs/_docs/contributing/index.md new file mode 100644 index 000000000000..6cf0def2d5e2 --- /dev/null +++ b/docs/_docs/contributing/index.md @@ -0,0 +1,4 @@ +--- +layout: index +title: Contributing +--- diff --git a/docs/_docs/index.md b/docs/_docs/index.md index 839d14d16308..abbca4c69bb2 100644 --- a/docs/_docs/index.md +++ b/docs/_docs/index.md @@ -1,6 +1,6 @@ --- -layout: doc-page -redirectFrom: docs/index.html +layout: index +redirectFrom: /docs/index.html --- Dotty is the project name for technologies that are considered for inclusion in Scala 3. Scala has @@ -16,7 +16,3 @@ be a big step towards realizing the full potential of these ideas. Its main obje In this documentation you will find information on how to use the Dotty compiler on your machine, navigate through the code, setup Dotty with your favorite IDE and more! -Table of Contents -================= -{% assign titles = sidebar.titles %} -{% include "table-of-contents" %} diff --git a/docs/_docs/internals/index.md b/docs/_docs/internals/index.md new file mode 100644 index 000000000000..a1ae2b80c5c8 --- /dev/null +++ b/docs/_docs/internals/index.md @@ -0,0 +1,5 @@ +--- +layout: index +title: Internals +--- + diff --git a/docs/_docs/reference/changed-features/changed-features.md b/docs/_docs/reference/changed-features/changed-features.md index 05a138b396fa..e8eb2ac6714b 100644 --- a/docs/_docs/reference/changed-features/changed-features.md +++ b/docs/_docs/reference/changed-features/changed-features.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Other Changed Features" movedTo: https://docs.scala-lang.org/scala3/reference/changed-features.html --- diff --git a/docs/_docs/reference/contextual/contextual.md b/docs/_docs/reference/contextual/contextual.md index a2fe095c44c0..67200a7626ca 100644 --- a/docs/_docs/reference/contextual/contextual.md +++ b/docs/_docs/reference/contextual/contextual.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Contextual Abstractions" movedTo: https://docs.scala-lang.org/scala3/reference/contextual.html --- diff --git a/docs/_docs/reference/dropped-features/dropped-features.md b/docs/_docs/reference/dropped-features/dropped-features.md index f4cd72942949..51fbbc8a26ab 100644 --- a/docs/_docs/reference/dropped-features/dropped-features.md +++ b/docs/_docs/reference/dropped-features/dropped-features.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Dropped Features" movedTo: https://docs.scala-lang.org/scala3/reference/dropped-features.html --- diff --git a/docs/_docs/reference/enums/enums-index.md b/docs/_docs/reference/enums/enums-index.md index 794c0130c9ec..c49afaffea0d 100644 --- a/docs/_docs/reference/enums/enums-index.md +++ b/docs/_docs/reference/enums/enums-index.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Enums" movedTo: https://docs.scala-lang.org/scala3/reference/enums.html --- diff --git a/docs/_docs/reference/experimental/named-typeargs.md b/docs/_docs/reference/experimental/named-typeargs.md index b9b4f7f33d69..2b83349f2e13 100644 --- a/docs/_docs/reference/experimental/named-typeargs.md +++ b/docs/_docs/reference/experimental/named-typeargs.md @@ -1,7 +1,7 @@ --- layout: doc-page title: "Named Type Arguments" -redirectFrom: reference/other-new-features/named-typeargs.html +redirectFrom: /docs/reference/other-new-features/named-typeargs.html movedTo: https://docs.scala-lang.org/scala3/reference/experimental/named-typeargs.html --- diff --git a/docs/_docs/reference/experimental/overview.md b/docs/_docs/reference/experimental/overview.md index 2644de0d864e..96677ef16b0b 100644 --- a/docs/_docs/reference/experimental/overview.md +++ b/docs/_docs/reference/experimental/overview.md @@ -1,7 +1,8 @@ --- layout: doc-page -title: "Overview" +title: "Experimental" movedTo: https://docs.scala-lang.org/scala3/reference/experimental/overview.html +redirectFrom: overview.html --- ### Experimental language features diff --git a/docs/_docs/reference/language-versions/language-versions.md b/docs/_docs/reference/language-versions/language-versions.md index e98aba32fd34..c38538d3a82a 100644 --- a/docs/_docs/reference/language-versions/language-versions.md +++ b/docs/_docs/reference/language-versions/language-versions.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Language Versions" --- diff --git a/docs/_docs/reference/metaprogramming/metaprogramming.md b/docs/_docs/reference/metaprogramming/metaprogramming.md index d2f210187337..6b682d3ce237 100644 --- a/docs/_docs/reference/metaprogramming/metaprogramming.md +++ b/docs/_docs/reference/metaprogramming/metaprogramming.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Metaprogramming" movedTo: https://docs.scala-lang.org/scala3/reference/metaprogramming.html --- diff --git a/docs/_docs/reference/new-types/new-types.md b/docs/_docs/reference/new-types/new-types.md index dd2d1036d2e6..be98f42ec70d 100644 --- a/docs/_docs/reference/new-types/new-types.md +++ b/docs/_docs/reference/new-types/new-types.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "New Types" movedTo: https://docs.scala-lang.org/scala3/reference/new-types.html --- diff --git a/docs/_docs/reference/other-new-features/other-new-types.md b/docs/_docs/reference/other-new-features/other-new-types.md index 85e768833a71..6264bd95c3f1 100644 --- a/docs/_docs/reference/other-new-features/other-new-types.md +++ b/docs/_docs/reference/other-new-features/other-new-types.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Other New Features" movedTo: https://docs.scala-lang.org/scala3/reference/other-new-features.html --- diff --git a/docs/_docs/reference/overview.md b/docs/_docs/reference/overview.md index 051ba4b124cc..9b184a7408ba 100644 --- a/docs/_docs/reference/overview.md +++ b/docs/_docs/reference/overview.md @@ -1,7 +1,8 @@ --- layout: doc-page -title: "Overview" +title: "Reference" movedTo: https://docs.scala-lang.org/scala3/reference/overview.html +redirectFrom: overview.html --- Scala 3 implements many language changes and improvements over Scala 2. diff --git a/docs/_docs/usage/index.md b/docs/_docs/usage/index.md new file mode 100644 index 000000000000..dc0f09eaf547 --- /dev/null +++ b/docs/_docs/usage/index.md @@ -0,0 +1,4 @@ +--- +layout: index +title: Usage +--- diff --git a/docs/_docs/usage/scaladoc/index.md b/docs/_docs/usage/scaladoc/index.md index dc53c01db666..7cb4d3b04a6b 100644 --- a/docs/_docs/usage/scaladoc/index.md +++ b/docs/_docs/usage/scaladoc/index.md @@ -1,5 +1,5 @@ --- -layout: doc-page +layout: index title: "Scaladoc" --- diff --git a/docs/_layouts/index.html b/docs/_layouts/index.html index 5be2d9794299..29d875645428 100644 --- a/docs/_layouts/index.html +++ b/docs/_layouts/index.html @@ -1,4 +1,15 @@ --- -layout: main +layout: static-site-main --- -

{{ content }}

+

{{ page.title }}

+ +{{ content }} + +

Table of Contents

+ diff --git a/docs/sidebar.yml b/docs/sidebar.yml index 1dba1b199450..f65c7fed0e69 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -2,6 +2,7 @@ index: index.md subsection: - title: Usage directory: docs/usage + index: usage/index.md subsection: - page: usage/sbt-projects.md - page: usage/ide-support.md @@ -17,8 +18,8 @@ subsection: - page: usage/scaladoc/static-site.md - title: Reference directory: docs/reference + index: reference/overview.md subsection: - - page: reference/overview.md - title: New Types index: reference/new-types/new-types.md subsection: @@ -137,8 +138,8 @@ subsection: - page: reference/dropped-features/wildcard-init.md - title: Experimental Features directory: experimental + index: reference/experimental/overview.md subsection: - - page: reference/experimental/overview.md - page: reference/experimental/canthrow.md - page: reference/experimental/erased-defs.md - page: reference/experimental/erased-defs-spec.md @@ -157,6 +158,7 @@ subsection: - page: reference/features-classification.md - title: Contributing directory: docs/contributing + index: contributing/index.md subsection: - page: contributing/contribute-knowledge.md - page: contributing/getting-started.md @@ -175,6 +177,7 @@ subsection: - page: contributing/procedures/vulpix.md - title: Internals directory: docs/internals + index: internals/index.md subsection: - page: internals/backend.md - page: internals/classpaths.md diff --git a/project/Build.scala b/project/Build.scala index 0b8318f35e05..56e061b6ea8c 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1392,6 +1392,7 @@ object Build { .add(OutputDir("scaladoc/output/reference")) .add(SiteRoot(s"${temp.getAbsolutePath}/docs")) .add(ProjectName("Scala 3 Reference")) + .remove[VersionsDictionaryUrl] .add(SourceLinks(List( dottySrcLink(referenceVersion, temp.getAbsolutePath + "=") ))) diff --git a/project/resources/referenceReplacements/sidebar.yml b/project/resources/referenceReplacements/sidebar.yml index 7d43febb562f..a8453449e73e 100644 --- a/project/resources/referenceReplacements/sidebar.yml +++ b/project/resources/referenceReplacements/sidebar.yml @@ -1,6 +1,5 @@ index: reference/overview.md subsection: - - page: reference/overview.md - title: New Types index: reference/new-types/new-types.md subsection: @@ -119,8 +118,8 @@ subsection: - page: reference/dropped-features/wildcard-init.md - title: Experimental Features directory: experimental + index: reference/experimental/overview.md subsection: - - page: reference/experimental/overview.md - page: reference/experimental/canthrow.md - page: reference/experimental/erased-defs.md - page: reference/experimental/erased-defs-spec.md @@ -136,4 +135,4 @@ subsection: - page: reference/language-versions/source-compatibility.md - page: reference/language-versions/binary-compatibility.md - page: reference/soft-modifier.md - - page: reference/features-classification.md \ No newline at end of file + - page: reference/features-classification.md diff --git a/scaladoc-testcases/docs/_docs/docs/f1.md b/scaladoc-testcases/docs/_docs/docs/f1.md index f5b5556f90ac..e9190567c5b9 100644 --- a/scaladoc-testcases/docs/_docs/docs/f1.md +++ b/scaladoc-testcases/docs/_docs/docs/f1.md @@ -1,7 +1,7 @@ --- layout: static-site-main redirectFrom: - - docs/fr.html - - docs/my-custom-link + - /docs/fr.html + - /docs/my-custom-link --- F1 diff --git a/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala b/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala index c8388a8112bd..86234812732e 100644 --- a/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala +++ b/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala @@ -39,7 +39,7 @@ case class LoadedTemplate( ) def resolveToHtml(ctx: StaticSiteContext): ResolvedPage = - val posts = children.map(_.lazyTemplateProperties(ctx)) + val posts = children.filterNot(_.hidden).map(_.lazyTemplateProperties(ctx)) def getMap(key: String) = templateFile.settings.getOrElse(key, Map.empty).asInstanceOf[Map[String, Object]] val sourceLinks = if !file.exists() then Nil else diff --git a/scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala b/scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala index 9f14442a7dbe..48c2acb745af 100644 --- a/scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala +++ b/scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala @@ -46,10 +46,12 @@ class StaticSiteContext( allTemplates.flatMap { loadedTemplate => val redirectFrom = loadedTemplate.templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]].get("redirectFrom") def redirectToTemplate(redirectFrom: String) = - val fakeFile = new File(docsPath.toFile, redirectFrom) - val driFrom = driFor(fakeFile.toPath) + val path = if redirectFrom.startsWith("/") + then relativizeFrom.resolve(redirectFrom.drop(1)) + else loadedTemplate.file.toPath.resolveSibling(redirectFrom) + val driFrom = driFor(path) val driTo = driFor(loadedTemplate.file.toPath) - (LoadedTemplate(layouts("redirect"), List.empty, fakeFile), driFrom, driTo) + (LoadedTemplate(layouts("redirect"), List.empty, path.toFile), driFrom, driTo) redirectFrom.map { case redirectFrom: String => Seq(redirectToTemplate(redirectFrom)) case redirects: List[?] => redirects.asInstanceOf[List[String]].map(redirectToTemplate) From 4b3e218531341b82298aab956689cc1961f454f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Zyba=C5=82a?= Date: Fri, 11 Mar 2022 15:16:53 +0100 Subject: [PATCH 2/3] Turn off not checked and failing snippets --- .../src/code-snippets/CodeSnippets.scala | 2 +- .../comments/markdown/SnippetRenderer.scala | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scaladoc-js/common/src/code-snippets/CodeSnippets.scala b/scaladoc-js/common/src/code-snippets/CodeSnippets.scala index 6595aa77c372..47f301705f30 100644 --- a/scaladoc-js/common/src/code-snippets/CodeSnippets.scala +++ b/scaladoc-js/common/src/code-snippets/CodeSnippets.scala @@ -179,7 +179,7 @@ class CodeSnippets: val buttonsSection = getButtonsSection(snippet) buttonsSection.foreach(s => s.appendChild(copyButton) - if !snippet.hasAttribute("hasContext") then { + if snippet.hasAttribute("runnable") then { s.appendChild(toScastieButton) s.appendChild(runButton) s.appendChild(exitButton) diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala index 9c95ae06d9ee..65e14fa343c4 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala @@ -5,7 +5,6 @@ import com.vladsch.flexmark.html._ import util.HTML._ import dotty.tools.scaladoc.snippets._ -import dotty.tools.scaladoc.util.HTML._ case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.empty, messages: Seq[String] = Seq.empty, attributes: Map[String, String] = Map.empty): def withClass(cls: String) = this.copy(classes = classes + cls) @@ -134,15 +133,26 @@ object SnippetRenderer: div(cls := "snippet-label")(name) ).toString - def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean): String = + def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean, success: Boolean): String = val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML) val codeHTML = s"""${transformedLines.mkString("")}""" - s"""
$codeHTML
${snippetName.fold("")(snippetLabel(_))}
""" + val isRunnable = !hasContext && success + val attrs = Seq( + Option.when(isRunnable)(Attr("runnable") := "") + ).flatten + div(cls := "snippet", Attr("scala-snippet") := "", attrs)( + div(cls := "buttons")(), + pre( + raw(codeHTML) + ), + raw(snippetName.fold("")(snippetLabel(_))) + ).toString def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String = renderSnippetWithMessages( node.name, node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq, node.compilationResult.toSeq.flatMap(_.messages), - node.hasContext + node.hasContext, + node.compilationResult.fold(false)(_.isSuccessful) ) From 4fc49510958da83a3d4dc7915738f4683eee1ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Zyba=C5=82a?= Date: Tue, 15 Mar 2022 11:36:00 +0100 Subject: [PATCH 3/3] Rename property posts to pages --- docs/_blog/index.html | 2 +- docs/_docs/usage/dottydoc.md | 2 +- docs/_layouts/index.html | 4 ++-- scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/_blog/index.html b/docs/_blog/index.html index b1ad4787b41b..055b069b303d 100644 --- a/docs/_blog/index.html +++ b/docs/_blog/index.html @@ -6,7 +6,7 @@

{{ page.title }}

    - {% for post in site.posts %} + {% for post in site.subpages %}
  • {{ post.title }} diff --git a/docs/_docs/usage/dottydoc.md b/docs/_docs/usage/dottydoc.md index 28c29606a301..f7010a0ab3b8 100644 --- a/docs/_docs/usage/dottydoc.md +++ b/docs/_docs/usage/dottydoc.md @@ -107,7 +107,7 @@ An example of this would be: To be rendered as templates, each blog post should have front-matter and a `layout` declaration. -The posts are also available in the variable `site.posts` throughout the site. +The posts are also available in the variable `site.subpages` throughout the site. The fields of these objects are the same as in `[BlogPost](dotty.tools.dottydoc.staticsite.BlogPost)`. diff --git a/docs/_layouts/index.html b/docs/_layouts/index.html index 29d875645428..72e3bb609d56 100644 --- a/docs/_layouts/index.html +++ b/docs/_layouts/index.html @@ -7,9 +7,9 @@

    {{ page.title }}

    Table of Contents

    diff --git a/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala b/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala index 86234812732e..659409f2ef67 100644 --- a/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala +++ b/scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala @@ -39,7 +39,7 @@ case class LoadedTemplate( ) def resolveToHtml(ctx: StaticSiteContext): ResolvedPage = - val posts = children.filterNot(_.hidden).map(_.lazyTemplateProperties(ctx)) + val subpages = children.filterNot(_.hidden).map(_.lazyTemplateProperties(ctx)) def getMap(key: String) = templateFile.settings.getOrElse(key, Map.empty).asInstanceOf[Map[String, Object]] val sourceLinks = if !file.exists() then Nil else @@ -50,7 +50,7 @@ case class LoadedTemplate( ctx.sourceLinks.pathTo(actualPath, operation = "edit", optionalRevision = Some("master")).map("editSource" -> _) val updatedSettings = templateFile.settings ++ ctx.projectWideProperties + - ("site" -> (getMap("site") + ("posts" -> posts))) + ("urls" -> sourceLinks.toMap) + + ("site" -> (getMap("site") + ("subpages" -> subpages))) + ("urls" -> sourceLinks.toMap) + ("page" -> (getMap("page") + ("title" -> templateFile.title.name))) templateFile.resolveInner(RenderingContext(updatedSettings, ctx.layouts))(using ctx)