From: Ben Soares Date: Mon, 9 May 2022 10:33:27 +0000 (+0100) Subject: JAL-3989 Code tidying, added JVL_HEADER for older versions of Jalview, allow time... X-Git-Tag: Release_2_11_2_6~64^2~7 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5e5545a5a719207cdab4c9b16baf7cd18c16bfba;p=jalview.git JAL-3989 Code tidying, added JVL_HEADER for older versions of Jalview, allow time in release date header --- diff --git a/build.gradle b/build.gradle index e6cc590..18af797 100644 --- a/build.gradle +++ b/build.gradle @@ -2397,7 +2397,9 @@ def hugoTemplateSubstitutions(String input, Map extras=null) { GIT_BRANCH: gitBranch, VERSION: JALVIEW_VERSION, JAVA_VERSION: JAVA_VERSION, - VERSION_UNDERSCORES: JALVIEW_VERSION_UNDERSCORES + VERSION_UNDERSCORES: JALVIEW_VERSION_UNDERSCORES, + DRAFT: "false", + JVL_HEADER: "" ] def output = input if (extras != null) { @@ -2411,6 +2413,46 @@ def hugoTemplateSubstitutions(String input, Map extras=null) { return output } +def mdFileComponents(File mdFile, def dateOnly=false) { + def map = [:] + def content = "" + if (mdFile.exists()) { + def inFrontMatter = false + def firstLine = true + mdFile.eachLine { line -> + if (line.matches("---")) { + def prev = inFrontMatter + inFrontMatter = firstLine + if (inFrontMatter != prev) + return false + } + if (inFrontMatter) { + def m = null + if (m = line =~ /^date:\s*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/) { + map["date"] = new Date().parse("yyyy-MM-dd HH:mm:ss", m[0][1]) + } else if (m = line =~ /^date:\s*(\d{4}-\d{2}-\d{2})/) { + map["date"] = new Date().parse("yyyy-MM-dd", m[0][1]) + } else if (m = line =~ /^channel:\s*(\S+)/) { + map["channel"] = m[0][1] + } else if (m = line =~ /^version:\s*(\S+)/) { + map["version"] = m[0][1] + } else if (m = line =~ /^\s*([^:]+)\s*:\s*(\S.*)/) { + map[ m[0][1] ] = m[0][2] + } + if (dateOnly && map["date"] != null) { + return false + } + } else { + if (dateOnly) + return false + content += line+"\n" + } + firstLine = false + } + } + return dateOnly ? map["date"] : [map, content] +} + task hugoTemplates { group "website" description "Create partially populated md pages for hugo website build" @@ -2420,9 +2462,7 @@ task hugoTemplates { def templateFiles = fileTree(dir: hugoTemplatesDir) def releaseMdFile = file("${jalviewDir}/${releases_dir}/release-${JALVIEW_VERSION_UNDERSCORES}.md") def whatsnewMdFile = file("${jalviewDir}/${whatsnew_dir}/whatsnew-${JALVIEW_VERSION_UNDERSCORES}.md") - def releaseTemplateFile = file("${jalviewDir}/${releases_template}") - def releasesTemplateFile = file("${jalviewDir}/${releases_template}") - def whatsnewTemplateFile = file("${jalviewDir}/${whatsnew_template}") + def oldJvlFile = file("${jalviewDir}/${hugo_old_jvl}") doFirst { // specific release template for version archive @@ -2432,43 +2472,21 @@ task hugoTemplates { def givenChannel = null def givenVersion = null if (CHANNEL == "RELEASE") { - def releasesHtmlFile = file("${helpSourceDir}/${releases_html}") - //MD_PARSE - if (releaseMdFile.exists()) { - def inFrontMatter = false - def itemComment = null - def firstLine = true - releaseMdFile.eachLine { line -> - if (line.matches("---")) { - def prev = inFrontMatter - inFrontMatter = firstLine - if (inFrontMatter != prev) - return - } - if (inFrontMatter) { - def m = null - if (m = line =~ /^date:\s*([0-9\-]+)/) { - givenDate = new Date().parse("yyyy-MM-dd", m[0][1]) - } else if (m = line =~ /^channel:\s*(\S+)/) { - givenChannel = m[0][1] - } else if (m = line =~ /^version:\s*(\S+)/) { - givenVersion = m[0][1] - } - } else { - changes += line+"\n" - } - firstLine = false - } - if (givenVersion != null && givenVersion != JALVIEW_VERSION) { - throw new GradleException("'version' header (${givenVersion}) found in ${releaseMdFile} does not match JALVIEW_VERSION (${JALVIEW_VERSION})") - } - if (whatsnewMdFile.exists()) { - whatsnew = whatsnewMdFile.text - } - def content = releaseMdFile.text + def (map, content) = mdFileComponents(releaseMdFile) + givenDate = map.date + givenChannel = map.channel + givenVersion = map.version + changes = content + if (givenVersion != null && givenVersion != JALVIEW_VERSION) { + throw new GradleException("'version' header (${givenVersion}) found in ${releaseMdFile} does not match JALVIEW_VERSION (${JALVIEW_VERSION})") } + + if (whatsnewMdFile.exists()) + whatsnew = whatsnewMdFile.text } + def oldJvl = oldJvlFile.exists() ? oldJvlFile.collect{it} : [] + def changesHugo = null if (changes != null) { changesHugo = '
\n\n' @@ -2485,7 +2503,7 @@ task hugoTemplates { section = section.replaceAll(/[^a-z0-9_\-]/, "") changesHugo += "
\n\n" inSection = true - } else if (m = line =~ /^(\s*-\s*)(.*)/) { + } else if (m = line =~ /^(\s*-\s*)(.*?)()?\s*$/) { def comment = m[0][2].trim() if (comment != "") { comment = comment.replaceAll('"', """) @@ -2497,6 +2515,8 @@ task hugoTemplates { newline += m[0][3].trim() if (issuekeys.size() > 0) newline += " {{< jal issue=\"${issuekeys.join(",")}\" alt=\"${comment}\" >}}" + if (m[0][4] != null) + newline += m[0][4] line = newline } } @@ -2527,21 +2547,105 @@ task hugoTemplates { [ WHATSNEW: whatsnew, CHANGES: changesHugo, - DATE: givenDate.format("yyyy-MM-dd") + DATE: givenDate == null ? "" : givenDate.format("yyyy-MM-dd"), + DRAFT: givenDate == null ? "true" : "false", + JVL_HEADER: oldJvl.contains(JALVIEW_VERSION) ? "jvl: true" : "" ] ) } } + inputs.file(oldJvlFile) inputs.dir(hugoTemplatesDir) - inputs.file(releaseTemplateFile) - inputs.file(releasesTemplateFile) - inputs.file(whatsnewTemplateFile) inputs.property("JALVIEW_VERSION", { JALVIEW_VERSION }) inputs.property("CHANNEL", { CHANNEL }) } +def getMdDate(File mdFile) { + return mdFileComponents(mdFile, true) +} + +def getMdSections(String content) { + def sections = [:] + def sectionContent = "" + def sectionName = null + content.eachLine { line -> + def m = null + if (m = line =~ /^##([^#].*)$/) { + if (sectionName != null) { + sections[sectionName] = sectionContent + sectionName = null + sectionContent = "" + } + sectionName = m[0][1].trim() + sectionName = sectionName.toLowerCase() + sectionName = sectionName.replaceAll(/ +/, "_") + sectionName = sectionName.replaceAll(/[^a-z0-9_\-]/, "") + } else if (sectionName != null) { + sectionContent += line+"\n" + } + } + return sections +} + +task releasesTemplates { + def releasesTemplateFile = file("${jalviewDir}/${releases_template}") + def whatsnewTemplateFile = file("${jalviewDir}/${whatsnew_template}") + def releasesHtmlFile = file("${helpSourceDir}/${releases_html}") + def whatsnewHtmlFile = file("${helpSourceDir}/${whatsnew_html}") + def releasesMdDir = "${jalviewDir}/${releases_dir}" + def whatsnewMdDir = "${jalviewDir}/${whatsnew_dir}" + + doFirst { + def releaseFiles = fileTree(dir: releasesMdDir, include: "release-*.md") + def releaseFilesDates = releaseFiles.collectEntries { + [(it): getMdDate(it)] + } + releaseFiles = releaseFiles.sort { a,b -> releaseFilesDates[a].compareTo(releaseFilesDates[b]) } + + def releasesTemplate = releasesTemplateFile.text + def m = releasesTemplate =~ /(?s)__VERSION_LOOP_START__(.*)__VERSION_LOOP_END__/ + def versionTemplate = m[0][1] + + def versions = "" + releaseFiles.each { rFile -> + def (rMap, rContent) = mdFileComponents(rFile) + + def vm = JALVIEW_VERSION =~ /^(.+)\.(\d+)$/ + def branchVersion = m[0][1] + def minorVersion = m[0][2] + def displayDate = releaseFilesDates[rFile].format("d MMMMM yyyy") + + def rContentSections = getMdSections(rContent) + + def rVersion = versionTemplate + if (rVersion != "") { + rVersion = hugoTemplateSubstitutions(rVersion, + [ + BRANCH_VERSION: branchVersion, + MINOR_VERSION: minorVersion, + DISPLAY_DATE: displayDate, + NEW_FEATURES: rContentSections["new_features"], + KNOWN_ISSUES: rContentSections["known_issues"] + ] + ) + } + + println("RVERSION='$rVersion'") + + + } + } + + inputs.file(releasesTemplateFile) + inputs.file(whatsnewTemplateFile) + inputs.dir(releasesMdDir) + inputs.dir(whatsnewMdDir) + outputs.file(releasesHtmlFile) + outputs.file(whatsnewHtmlFile) +} + task helppages { dependsOn copyHelp diff --git a/gradle.properties b/gradle.properties index 58a5110..cd4bc4a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -58,6 +58,7 @@ shadow_jar_main_class = jalview.bin.Launcher jalview_name = Jalview +hugo_old_jvl = utils/hugo/old_jvl.txt hugo_build_dir = build/website/hugo hugo_data_installers_dir = data/installers hugo_version_archive_dir = content/development/archive @@ -65,6 +66,7 @@ hugo_templates_dir = utils/hugo/templates releases_template = help/templates/releases.html whatsnew_template = help/templates/whatsNew.html releases_html = html/releases.html +whatsnew_html = html/whatsNew.html whatsnew_dir = help/markdown/whatsnew releases_dir = help/markdown/releases # these are going to be used in the future to gather website release files together diff --git a/utils/hugo/old_jvl.txt b/utils/hugo/old_jvl.txt new file mode 100644 index 0000000..5309f1b --- /dev/null +++ b/utils/hugo/old_jvl.txt @@ -0,0 +1,25 @@ +2.0 +2.03 +2.3 +2.4 +2.5 +2.5.1 +2.6 +2.6.1 +2.7 +2.8 +2.8.0b1 +2.8.1 +2.8.2 +2.8.2b1 +2.9 +2.10.0 +2.10.1 +2.10.2 +2.10.2b1 +2.10.2b2 +2.10.3 +2.10.3b1 +2.10.4 +2.10.4b1 +2.10.5 diff --git a/utils/hugo/templates/content/development/archive/Version-__VERSION_UNDERSCORES__/_index.md b/utils/hugo/templates/content/development/archive/Version-__VERSION_UNDERSCORES__/_index.md index 54a11dc..2f4558e 100644 --- a/utils/hugo/templates/content/development/archive/Version-__VERSION_UNDERSCORES__/_index.md +++ b/utils/hugo/templates/content/development/archive/Version-__VERSION_UNDERSCORES__/_index.md @@ -6,9 +6,11 @@ publishdate: __DATE__ title: __APPLICATION_NAME__ __VERSION__ siderendertoc: false cascade: + draft: __DRAFT__ release_date: __DATE__ version: "__VERSION__" jalviewjslink: false + __JVL_HEADER__ --- __WHATSNEW__