From: Georgios Atheridis Date: Sun, 12 Feb 2023 22:20:23 +0000 (+0000) Subject: Generate html Files Through Build Scripts X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=b19e07c9b3e5af9dc7cafb6bce18da87196a9dc7;p=personal%2Fsigma.git Generate html Files Through Build Scripts Users can now create build scripts in python that will allow them to generate html files dynamically--based on other data. This is useful for cases where one has a blog with posts being tagged, it is now possible to create an html file for each tag and group all posts within that tag's page. --- diff --git a/README b/README index 4df6195..fb5d978 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ sigma is a static site generator written in python data.toml: ---------- It is used to define variables for each file. Variables in the root are -global and are inherited by their children. If a child has a variable +global and are inherited by their children. If a child has a variable of the same name, then the child's variable is used instead. ----------------------------------------------------------------------- @@ -15,6 +15,8 @@ Keywords: - `_TEMPLATES` specifies the template directory - `_OUT` designates the directory where the output files go - `_DATE_FORMAT` designates the date format to use when using `_date` +- `_EXT` is used to find the file extension; it is assigned during + execution and should not be changed. + `self` the file which invoked the template + `_extend` the template which the file should invoke @@ -47,6 +49,22 @@ Functionality: │ ├─ _test.py ``` Where the file names inside the directory become the variables of the - file. Python files are not run here, as they will often be used to - write code which can then be imported into the _value variable. Files - that are meant to be ran should go into the templates directory. + file. Python files are not run here, as they will often be used to + write code which can then be imported into the `_value` variable. + Files that are meant to be ran should go into the templates directory. + + +- Ability to create html files on the fly using `_build.py` python + scripts. The `_value` variable when the script finishes will produce + the html files with their values. + + The `_value` variable must be a list containing 2-tuples. Each 2-tuple + is an html file, the first element of the 2-tuple is a list containing + a split path to the html file, with the last value being the name of + the file without the extension; for example, the path `post/one.html` + will have the list ["post", "one"]. The second value of the 2-tuple is + the contents of the html file. + + This is useful for cases where the amount of files changes dynamically + based on content. For example, having an html file for each tag to + group posts by. diff --git a/TODO b/TODO index d37fbc1..7e47ebb 100644 --- a/TODO +++ b/TODO @@ -1,19 +1,12 @@ TODO ==== -- Allow for a _build variable which will produce html files through - key-value pairs. Directories will also be able to be created by - having another key-value pair inside of the value. This will allow - for recursive creation of html files and directories. +- Do not update files that haven't changed. Include `data.toml` values. - If the _build variable is a python file inside of the pages directory - it will run the python file and the _value variable inside the file - will result in the value of the _build variable. +- Refactor code so a lot of logic isn't duplicated in multiple places. -- Do not update files that haven't changed. Include data.toml values. - -- Allow any executable to be executed as a template. Its standard - output becomes the _value of that template. Make sure to transfer +- Allow any executable to be executed as a template. Its standard + output becomes the `_value` of that template. Make sure to transfer appropriate data to the executable. -- Add logging. +- Add logging, docstrings, and comments. diff --git a/data.toml b/data.toml index 076926d..8ae5419 100644 --- a/data.toml +++ b/data.toml @@ -18,10 +18,32 @@ _email = "georgios@atheridis.org" [index] _name = "Home" _title = "My Blog" +_nav = 0 + +[final] +_nav = 5 + +[textfile] +_nav = 20 + +[about] +_nav = 10 + +[page_dir.index] +_name = "Page Dir" +_nav = 30 [posts] _extend = "post.html" +[posts.tags] +_extend = "base.html" + +[posts.tags.index] +_name = "Tags" +_nav = 40 + + [posts.example] _owner = "John Doe" _email = "john_doe@example.com" @@ -39,8 +61,12 @@ _tags = ["test", "post"] [posts.other] _title = "Another Post" _description = "The description of another post" -_tags = ["other", "post"] +_tags = ["other", "post", "sigma"] [posts.other._table] name = ["Georgios Atheridis", "John Doe", "Jane Doe"] email = ["georgios@atheridis.org", "johndoe@example.com", "janedoe@example.com"] "phone number" = ["1234567890", "0777777777"] + +[posts.python-code] +_title = "Python Code" +_tags = ["post", "python", "example"] diff --git a/pages/final.md b/pages/final.md new file mode 100644 index 0000000..facbd28 --- /dev/null +++ b/pages/final.md @@ -0,0 +1 @@ +# Is this a markdown file? diff --git a/pages/index.html b/pages/index.html deleted file mode 100644 index 6c835c9..0000000 --- a/pages/index.html +++ /dev/null @@ -1,2 +0,0 @@ -

These are my posts

-{% file 'scripts/build_posts.py' %} diff --git a/pages/index.md b/pages/index.md new file mode 100644 index 0000000..6c835c9 --- /dev/null +++ b/pages/index.md @@ -0,0 +1,2 @@ +

These are my posts

+{% file 'scripts/build_posts.py' %} diff --git a/pages/posts/_build.py b/pages/posts/_build.py new file mode 100644 index 0000000..b616694 --- /dev/null +++ b/pages/posts/_build.py @@ -0,0 +1,36 @@ +tag_list = "