REBOL [
    Title: "Content Management"
    Date: 14-Jun-2002/9:51:42-7:00
    Version: 1.0.0
    File: %content-management.r
    Author: "Christopher Ross-Gill"
    Rights: "Chris and ALA readers"
    Purpose: "test"
    Email: pchadwick@internews.org
    Web: http://www.alistapart.com
    library: [
        level: 'intermediate 
        platform: 'all 
        type: 'module 
        domain: [broken ldc] 
        tested-under: none 
        support: none 
        license: none 
        see-also: none
    ]
]

content-block: read/lines %content.txt

while [empty-string: find content-block ""][remove empty-string]

structure: copy []

foreach paragraph content-block [
    parsed?: parse paragraph [
        "Site Title:" copy para to end
        (repend structure ['site-title trim para])
        |
        "New Page:" copy para to "("
        skip copy id to ")" skip
        (repend structure ['h1 trim para id])
        |
        "===" copy para to end
        (repend structure ['h2 para])
        |
        "..." copy para to end
        (repend structure ['li para])
    ]
    if not parsed? [repend structure ['p paragraph]]
]

format-text: func [text [string!]][
    replace/all text {&} {&}
    replace/all text { "} { “}
    if (first text) = #"^"" [replace text {"} {“}]
    replace/all text {"} {”}
    replace/all text { '} { ‘}
    if (first text) = #"'" [replace text {'} {‘}]
    replace/all text {'} {’}
    replace/all text {--} {–}
    replace/all text { - } {–}
    replace/all text {.  } {.  }

    parse/all text [
        any [
            thru {##}
            copy link to {##}
            2 skip
            copy hlink to {##}
            (
                href: {} hlink {}
                ]
            )
        ]
        to end
    ]

    parse/all text [
        any [
            thru {**} copy emphasised to {**}
            (
                replace text rejoin [
                    {**} emphasised {**}
                ] rejoin [
                    {} emphasised {}
                ]
            )
        ]
        to end
    ]

    replace/all text {@} {@}
return text ] punch-template: func [ site-title [string!] page-title [string!] page-menu [string!] page-content [string!] ][ template: read %template.html replace template <% page-title %> rejoin [site-title ": " page-title] replace template <% page-body %> rejoin [newline page-menu newline page-content newline] return template ] pages: copy [] menu: copy "" parse structure [ (append menu ) ] if not exists? %pages/ [make-dir %pages/] foreach [file content] pages [ write join %pages/ file punch-template title header menu content ]