@@ -19,21 +19,14 @@ object CopyDocs {
1919 */
2020 val outputDir = FileSystems .getDefault.getPath(" docs-for-dotty-page" )
2121
22- implicit def stringToFun (s : String ): MyParams => String = _ => s
23-
24- // Patterns, for convenience
25- val titlePattern = """ (?s)^(---\n.*?title: ([^\n]*).*?---)"""
26- val redirectFromPattern = """ (?s)^---.*?((redirectFrom: ([^\n]*)).*?---|---)"""
2722 val jekyllLinkPattern = """ \{\% link _overviews/scala3-reference(.*) %\}"""
2823 val jekyllLinkSubstitution = " ..$1"
2924 val jekyllLinkPattern2 = """ \{\% link _overviews/scala3-scaladoc(.*) %\}"""
3025 val jekyllLinkSubstitution2 = " .$1"
3126 val localLinkPattern = """ \((?!http|www)(.*).html\)"""
3227 val localLinkSubstitution = " ($1.md)"
3328
34- case class MyParams (newPath : String )
35-
36- val commonTransformations : List [(String , MyParams => String )] = List (
29+ val commonTransformations : Map [String , String ] = Map (
3730 jekyllLinkPattern -> jekyllLinkSubstitution,
3831 jekyllLinkPattern2 -> jekyllLinkSubstitution2,
3932 localLinkPattern -> localLinkSubstitution,
@@ -44,32 +37,26 @@ object CopyDocs {
4437 * The outer map is holding morphism `directory prefix` -> `List of transformations`.
4538 * The inner list is a collection of pairs `regex pattern` -> `substitution value`.
4639 */
47- val transformationMap : Map [String , List [( String , MyParams => String ) ]] = Map (
48- " docs/docs/usage/scaladoc/index.md" -> List (
40+ val transformationMap : Map [String , Map [ String , String ]] = Map (
41+ " docs/docs/usage/scaladoc/index.md" -> Map (
4942 (""" \{\{ site\.baseurl \}\}/resources/images/scala3/scaladoc/logo\.svg""" -> " images/scaladoc_logo.svg" ),
5043 ),
5144
52- " docs/docs/usage/scaladoc/site-versioning.md" -> List (
45+ " docs/docs/usage/scaladoc/site-versioning.md" -> Map (
5346 (""" /resources/images/scala3/scaladoc/nightly\.gif""" -> " images/scaladoc/nightly.gif" ),
5447 ),
5548
56- " docs/docs/usage/scaladoc/search-engine.md" -> List (
49+ " docs/docs/usage/scaladoc/search-engine.md" -> Map (
5750 (""" /resources/images/scala3/scaladoc/inkuire-1\.0\.0-M2_js_flatMap\.gif""" -> " images/scaladoc/inkuire-1.0.0-M2_js_flatMap.gif" ),
5851 ),
5952
60- " docs/docs/reference/other-new-features/explicit-nulls.md" -> List (
53+ " docs/docs/reference/other-new-features/explicit-nulls.md" -> Map (
6154 (""" /resources/images/scala3/explicit-nulls/explicit-nulls-type-hierarchy\.png""" -> " images/explicit-nulls/explicit-nulls-type-hierarchy.png" ),
6255 ),
6356
64- " docs/docs/reference/" -> (commonTransformations ++ List [(String , MyParams => String )](
65- (titlePattern -> ((p) => s " $$ 1 \n layout: doc-page \n title: $$ 2 \n movedTo: https://docs.scala-lang.org/scala3/reference/ ${p.newPath}.html \n --- " )),
66- (redirectFromPattern -> " ---\n $2" )
67- )),
57+ " docs/docs/reference/" -> commonTransformations,
6858
69- " docs/docs/usage/scaladoc/" -> (commonTransformations ++ List [(String , MyParams => String )](
70- (titlePattern -> s " $$ 1 \n layout: doc-page \n title: $$ 2 \n --- " ),
71- (redirectFromPattern -> " ---\n $2" )
72- )),
59+ " docs/docs/usage/scaladoc/" -> commonTransformations
7360 )
7461
7562 def copyDocs () = {
@@ -78,14 +65,24 @@ object CopyDocs {
7865 Files .createDirectories(newPath.getParent())
7966
8067 path.toString match {
81- case s if s.startsWith(" docs/docs/" ) =>
68+ case s if s.startsWith(" docs/docs/" ) && s.endsWith( " .md " ) =>
8269 val inputStream = Source .fromFile(path.toFile)(Codec .UTF8 )
8370 val fileContent = inputStream.getLines().mkString(" \n " )
8471
8572 new PrintStream (newPath.toFile) {
8673 val patterns = transformationMap.filter { case (k, v) => path.toString.startsWith(k) }.flatMap(_._2)
87- val params = MyParams (newPath = s.stripPrefix(" docs/docs/reference/" ).stripSuffix(" .md" ))
88- val transformed = patterns.foldLeft(fileContent) { case (res, (pattern, substitution)) => res.replaceAll(pattern, substitution(params)) }
74+ val _ :: frontMatter :: actualContent :: Nil = fileContent.split(" ---" , 3 ).toList
75+ write(" ---" .getBytes(" UTF8" ))
76+ val frontMatterSplitted = frontMatter.split(" \n (?=[^\\ s])" )
77+ val frontMatterUpdated = List (
78+ Some (" layout: doc-page" ),
79+ frontMatterSplitted.find(_.startsWith(" title" )),
80+ frontMatterSplitted.find(_.startsWith(" redirectFrom" )),
81+ if (s.startsWith(" docs/docs/reference/" )) Some (s " movedTo: https://docs.scala-lang.org/scala3/reference/ ${s.stripPrefix(" docs/docs/reference/" ).stripSuffix(" .md" )}.html " ) else None
82+ ).flatten.mkString(" \n " , " \n " , " \n " )
83+ write(frontMatterUpdated.getBytes(" UTF8" ))
84+ write(" ---\n " .getBytes(" UTF8" ))
85+ val transformed = patterns.foldLeft(actualContent) { case (res, (pattern, substitution)) => res.replaceAll(pattern, substitution) }
8986 write(transformed.getBytes(" UTF8" ))
9087 }
9188 case s =>
0 commit comments