ssg/CHANGELOG.md
2023-03-03 15:11:43 -05:00

8.4 KiB

Changelog

All notable changes to SSG will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.1.0

Added

  • Templates, SpecialPages, and Parts all have access to two related objects: tasks and taskTypes. The first is an instance of TaskContainer and can be used to access all of the Task instances for a given build. The second is in an instance of TaskTypeContainer and can be used to access the various TaskType instances for a given build. For example, one could use these together to obtain the output path of an html file from another task (assume one is in a .gsp file):

    def otherTask = tasks.findAllByType(taskTypes.textToHtmlFile).find { it.input.path == 'someText.md' }
    assert otherTask.output.htmlPath == 'someText.html'
    

    This is a complicated and experimental feature and may be changed frequently depending on future developments. 92c8108.

  • Templates, SpecialPages, and Parts all have access to a logger of type org.slf4j.Logger. 64f342a.

  • There is now the notion of a siteSpec, an object of type of SiteSpec. It is simmilar to the globals object in that it contains properties that are available in all Templates, SpecialPages, and Parts. Unlike globals, which contains user-defined keys, siteSpec contains (for now) the pre-defined keys baseUrl and title. To configure the siteSpec, add the following block to a build block in ssgBuilds.groovy:

    siteSpec {
        baseUrl = 'https://test.com' // or whatever, defaults to an empty string
        title = 'My Great Website' // or whatever, defaults to an empty string
    }
    

    Then use it in any Template, SpecialPage, or part like so:

    <%
        assert siteSpec.baseUrl == 'https://test.com' && siteSpec.title == 'My Great Website'
    %>
    

    111bdea, ef9e566.

  • Templates, SpecialPages, and Parts all have access to targetPath of type String representing the path of the 'output' file. For now, this is always a .html file.

    <%
        // in a template where the source text is 'foo/bar.md'
        assert targetPath == 'foo/bar.html'
    
        // in a special page whose path is 'special.gsp'
        assert targetPath == 'special.html'
    
        // in a part with a source text of 'foo/bar/hello.md'
        assert targetPath == 'foo/bar/hello.html'
    
        // in a part with a source special page of 'foo/bar/baz/special.gsp'
        assert targetParth == 'foo/bar/baz/special.html'
    %>
    

    6de83df, 06499a9.

  • Templates, SpecialPages, and Parts all have access to sourcePath of type String representing the path of the 'source' file: either a text file or a special page. In Templates, the 'source' comes from the path of the Text being rendered; in SpecialPages, this comes from the path of the SpecialPage being rendered (i.e., itself); in Parts, this comes from either the Template or SpecialPage which called (i.e., embedded) the Part.

    <%
        // in a template or part when rendering a text at 'home.md'
        assert sourcePath == 'home.md'
    
        // in a template or part when rendering a text at 'posts/helloWorld.md'
        assert sourcePath == 'posts/helloWorld.md'
    
        // in a special page or part when rendering a special page at 'foo/bar/specialPage.gsp'
        assert sourcePath == 'foo/bar/specialPage.gsp'
    %>
    

    0371d41, 9983685, 076bc9b, c5ac810.

  • Templates, SpecialPages, and Parts all have access to a urlBuilder of type PathBasedUrlBuilder (implementing UrlBuilder). It can be used to obtain both absolute (using siteSpec.baseUrl) and relative urls (to the current targetPath). Use it like so:

    <%
        // when targetPath == 'simple.html'
        assert urlBuilder.relative('images/test.jpg') == 'images/test.jpg'
    
        // when targetPath == 'nested/post.html'
        assert urlBuilder.relative('images/test.jpg') == '../images/test.jpg'
    
        // when baseUrl is 'https://test.com' and targetPath is 'simple.html'
        assert urlBuilder.absolute == 'https://test.com/simple.html
    
        // when baseUrl is 'https://test.com' and we want an absolute to another file
        assert urlBuilder.absolute('images/test.jpg') == 'https://test.com/images/test.jpg'
    %>
    

    Nota bene: likely will break on Windows since PathBasedUrlBuilder currently uses Java's Path api and paths would be thusly rendered using Windows-style backslashes. This will be explored in the future. 0371d41, 0762dc6, 60f4c14.

  • Parts have access to all other parts now via parts, an object of type EmbeddablePartsMap. For example:

    <% 
        // myPart.gsp
        out << parts['otherPart.gsp'].render()
    %>
    

    0e49414.

  • A tagBuilder object of type DynamicTagBuilder (implementing TagBuilder) is available in Templates, SpecialPages, and Parts.

    <%
        def simpleTag = tagBuilder.test()
        assert simpleTag == '<test />'
    
        def tagWithBody = tagBuilder.title 'Hello, World!'
        assert tagWithBody == '<title>Hello, World!</title>'
    
        def tagWithAttributes = tagBuilder.meta name: 'og:title', content: 'Hello, World!'
        assert tagWithAttributes == '<meta name="og:title" content="Hello, World!" />'
    
        def tagWithAttributesAndBody = tagBuilder.p([id: 'my-paragraph'], 'Hello, World!')
        assert tagWithAttributesAndBody == '<p id="my-paragraph">Hello, World!</p>'
    %>
    

    This is likely most useful for building simple, one-line html/xml tags. 93687d.

  • Parts have a text object of type EmbeddableText. If one is rendering a Part called from anything other than a Template (which has an associated text), this will be null. 34d9cd5.

Breaking Changes

  • The path of a file was stripped of its extension when previously referring to Texts or SpecialPages; now, the extension is present. For example:
    <%
        // suppose we have a text called 'test.md' and we are in a template, special page, or part
        assert texts['test'] == null
        assert texts['test.md'] != null
    %>
    
    0371d41.
  • The text object in Templates is now an instance of EmbeddableText instead of String. Thus, one must use text.render() to obtain the rendered text. 34d9cd5.
  • The frontMatter object is no longer available. Use text.frontMatter instead. eafc8cd, c5ac810.