| buildscript { |
| //have to apply here for this to be applied at the right time |
| apply from: file("gradle/deps.gradle") |
| initScript(buildscript) |
| } |
| apply from: file("gradle/utils.gradle") |
| apply plugin: 'org.jbake.site' |
| apply plugin: 'io.freefair.jsass-base' |
| |
| loadGlobals(globalsFile) |
| |
| //to build up content, assets, etc which JBake can process for us, we need to process: |
| //SASS files |
| //JS files |
| //Image files |
| //Any other content we want to preprocess |
| //Content files such as .html and .md which just need metadata/front matter |
| //GSP content templates which allow programming and replacement with Groovy templates |
| //and we need to place all of these files in the appropriate location for JBake to do its job |
| //...this means in either the content or the assets folders, and this will be the |
| //generatedAssetsDir and generatedContentDir |
| |
| task compileContentSass(type: io.freefair.gradle.plugins.jsass.SassCompile, |
| description: "Compiles the projects SaSS files to the build directory.", |
| group: "Build") { |
| sourceDir = contentDir |
| destinationDir = generatedAssetDir |
| includePaths = files(new File(contentDir, "css")) |
| } |
| |
| task preprocessContentAssets(type: Copy, |
| description: "Pre-processes all .css, .js (not in the minimize list), images, etc from the content directory into the generated assets directory", |
| group: "Build") { |
| from contentDir |
| into generatedAssetDir |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| |
| include "**/*.js", "**/.css", |
| "**/*.png", "**/*.gif", |
| "**/*.jpeg", "**/*.jpg", |
| "**/*.svg", "**/*.ttf", |
| "**/*.woff", "**/.htaccess" |
| |
| exclude "/templates/**" |
| } |
| |
| task preprocessContentStatics(type: Copy, |
| description: "Pre-processes all .html, .md, and possibly other files which have metadata/front matter in a side car file of the same name and extension with an extra .yml extension after that", |
| group: "Build") { |
| from contentDir |
| into generatedContentDir |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| include "**/*.html.yml", "**/*.md.yml", "**/*.html", "**/*.md" |
| exclude "/templates/**" |
| |
| def mergeList = [] |
| |
| eachFile { details -> |
| if(details.sourcePath.endsWith(".yml")) { |
| //we don't want to do anything else with this |
| //it will just be copied into the generated folder |
| //but will not be merged by |
| return |
| } |
| def contentFile = file("${contentDir}/${details.sourcePath}") |
| def ymlFile = file("${contentFile}.yml") |
| if(ymlFile.exists()) { |
| logger.info("Setting up merge for ${details.path}") |
| def mergeData = createMergeData(file("${generatedContentDir}/${details.path}.yml").absolutePath, |
| file("${generatedContentDir}/${details.path}").absolutePath) |
| mergeList << mergeData |
| } else { |
| logger.info("The content file ${contentFile} can not be merged because the corresponding YAML file ${ymlFile} was not found.") |
| } |
| } |
| doLast { |
| //let's merge up the metadata with the content yml+content from the merge map |
| mergeList.each { data -> |
| logger.info("Merging ${data.file} and ${data.yml}") |
| mergeContentAndMetadata(data) |
| } |
| } |
| } |
| |
| task preprocessTemplates(type: Copy, |
| description: "Pre-processes the templates for JBake to use for baking", |
| group: "Build") { |
| from templateDir |
| into generatedTemplateDir |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| include "**/*" |
| } |
| |
| task preprocessContentTemplates(type: Copy, |
| description: "Pre-processes the *.gsp and *.gsp.yml files under content for baking as Groovy templates; edit global.yml to add data used in content other than YAML front matter", |
| group: "Build") { |
| |
| def mergeList = [] |
| |
| filteringCharset 'UTF-8' |
| includeEmptyDirs false |
| |
| from contentDir |
| into generatedContentDir |
| |
| |
| //we need to do both of these to make sure we are or are not up to date |
| include "**/*.gsp", "**/*.gsp.yml" |
| |
| exclude "/templates/**" |
| |
| rename '(.*)\\.gsp', '$1' |
| |
| //expand the files using Groovy's SimpleTemplateEngine |
| //for processing content like templates are also processed |
| def props = [:] |
| props.putAll(globals) |
| expand props |
| |
| eachFile { details -> |
| if(details.sourcePath.endsWith(".yml")) { |
| //we don't want to do anything else with this |
| //it will just be copied into the generated folder |
| //but will not be merged by jbake as there will not |
| //be meta info |
| return |
| } |
| def contentFile = file("${contentDir}/${details.sourcePath}") |
| def ymlFile = file("${contentFile}.yml") |
| if(ymlFile.exists()) { |
| def mergeData = createMergeData(file("${generatedContentDir}/${details.path}.yml").absolutePath, |
| file("${generatedContentDir}/${details.path}").absolutePath) |
| mergeList << mergeData |
| } else { |
| throw new Exception("The content file ${contentFile} can not be processed because the corresponding YAML file ${ymlFile} was not found.") |
| } |
| } |
| doLast { |
| //let's merge up the metadata with the content yml+content from the merge map |
| mergeList.each { data -> |
| mergeContentAndMetadata(data) |
| } |
| } |
| |
| } |
| |
| task preprocessContent(dependsOn: ["compileContentSass", |
| "preprocessContentAssets", |
| "preprocessContentStatics", |
| "preprocessTemplates", |
| "preprocessContentTemplates"], |
| description: "Runs all preprocess tasks to prepare for a bake", |
| group: "Build") { |
| |
| } |
| |
| jbake { |
| groovyTemplatesVersion = "${libs.groovy}" |
| version = "${libs.jbake}" |
| //the following vars are set the way they are because the way the jbake plugin works |
| srcDirName = generatedDirRelativePath |
| destDirName = bakedDirRelativePath |
| //this will cause builds to be faster as only changes will be baked, |
| //and since it is in the build directory, can be cleaned |
| configuration["db.store"]="local" |
| configuration["db.path"]=cacheDir.absolutePath |
| configuration.putAll(globals) |
| } |
| |
| bake.mustRunAfter preprocessContent |
| |
| task buildSite(dependsOn: ["preprocessContent", "bake"], |
| description: "Runs the site build: preprocessContent and bake", |
| group: "Build") { |
| |
| } |
| |
| task("run", type: JavaExec, group: "Run", overwrite: true) { |
| |
| def wDir = new File(buildDir, "tomcat") |
| |
| doFirst { |
| wDir.mkdirs() |
| bakedDir.mkdirs() |
| } |
| |
| main "TomcatMain" |
| classpath buildscript.configurations.classpath + files("${rootProject.projectDir}/buildSrc/build/classes/main") |
| args = [bakedDir, 8080, "SHUTDOWN", 8081] |
| workingDir = wDir |
| } |
| |
| task("stop", type: JavaExec, group: "Run", overwrite: true) { |
| main "TomcatStopMain" |
| classpath buildscript.configurations.classpath + files("${rootProject.projectDir}/buildSrc/build/classes/main") |
| args = ["SHUTDOWN", 8081] |
| } |
| |
| wrapper { |
| gradleVersion = libs.gradle |
| } |