Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added replacement facility for page content. #104

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Commits on Aug 30, 2023

  1. Added replacement facility for page content.

    By using either command line replacement pairs or specifying a file
    with json defintions of replacements an arbitrary regexp ("pattern")
    can be detected and replaced with another string, including expanding
    captured groups in the pattern.
    
    The replacement phase is taking place just before upsert, so all other
    textual manipulations are done by that time.
    
    Replacements happen in a deterministic sequence. There are ample
    opportunities to get unexpected (but logically consistent) results
    by inadvertently result of a previous replacement.
    
    Format of json file:
    ```
    {
        "environment": [
            {
                "import": "<module name>",
                "path": "<source file>"
            }
        ],
        "replacements":[
            {
                "name": "<name - optional>",
                "pattern": "<regexp>",
                "new_value": "<string with optional group expansions>"
                "evaluate": <true|false - optional>
            },
        ]
    }
    ```
    The `environment` block is optional and used for very dynamic
    replacements. By specifying a python source file, it will be
    dynamically imported at run time. The `new_value` field can then specify
    a `<module>.<func>` that returns a string value. As an example, the
    following adds a replacement of "TODAY" to an iso-formatted datetime.
    
    ```
    {
        "environment": [
            {
                "import": "funcs",
                "path": "funcs.py"
            }
        ],
        "replacements":[
            {
                "name": "Todays date",
                "pattern": "TODAY",
                "new_value": "funcs.today"
                "evaluate": true
            },
        ]
    }
    ```
    
    Funcs.py:
    ```
    import datetime
    
    def today(term):
        return datetime.datetime.now().isoformat()
    ```
    
    The parameter `term` is a Match object as per using
    https://docs.python.org/3/library/re.html#re.subn.
    jhogstrom committed Aug 30, 2023
    Configuration menu
    Copy the full SHA
    6f5f63a View commit details
    Browse the repository at this point in the history