Compare commits
2 commits
c449f9d9ac
...
16278b0921
Author | SHA1 | Date | |
---|---|---|---|
16278b0921 | |||
e39a0b85e7 |
3 changed files with 32 additions and 18 deletions
1
.~lock.parser.py#
Normal file
1
.~lock.parser.py#
Normal file
|
@ -0,0 +1 @@
|
||||||
|
,chloe,chloe-msi,05.04.2025 12:28,file:///home/jrmer/.config/libreoffice/4;
|
44
README.md
44
README.md
|
@ -1,26 +1,38 @@
|
||||||
# python-webgen
|
# python-webgen
|
||||||
|
|
||||||
a set of python scripts and html templates to generate blog-style websites
|
A set of python scripts and html templates to generate blog-style websites.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
---
|
For built in help, use the `--help` option.
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
Welcome to your new KitsuDev Repo, ChloeCat! Feel free to make this place your own!
|
## General Usage:
|
||||||
|
|
||||||
## Make your first push!
|
### Basic usage:
|
||||||
Once you're ready to push your files, use these commands to get to your spot!
|
`python webgen.py <input folder> <output folder>`
|
||||||
```bash
|
This will use the default location for the template files (`./templates/`) and the css file (`./templates/stylesheet.css`).
|
||||||
git remote add origin https://kitsunes.dev/ChloeCat/python-webgen.git
|
This will also set the title to simply "Blog", use `--site_title` to change that.
|
||||||
git branch -M main
|
|
||||||
git push -uf origin main
|
|
||||||
```
|
|
||||||
|
|
||||||
Once you're all set, please [Make a README](https://www.makeareadme.com/)!
|
### Example use:
|
||||||
|
`python webgen.py --site_title "Chloe's Blog" --title_all --css_file ~/css/custom_v2.css ~/Blog/posts/ ~/Blog/output/`
|
||||||
|
|
||||||
---
|
This will generate a site with a title of "Chloe's Blog," which will be applied to the HTML title of all the articles, in addition to the article title.
|
||||||
Have fun, and happy coding!
|
It will also use a custom CSS file from `~/css/custom_v2.css` which is different from the default.
|
||||||
|
The posts will come from a folder in the `~/Blog/posts/` folder and the completed HTML files will be placed in `~/Blog/output/`.
|
||||||
|
|
||||||
-- Kio
|
## Availible Arguments:
|
||||||
|
|
||||||
(p.s. and while you're at it, say hi to pearl.)
|
| Argument | Description |
|
||||||
|
|-----------------|-----------------------------------------------------------------------------------------------------------------------|
|
||||||
|
|`input_path` |The folder to read the markdown files from. |
|
||||||
|
|`output_path` |The folder to place the final HTML files in. |
|
||||||
|
|`--template_path`|The folder where the template HTML snippets are. Default: `./templates/` |
|
||||||
|
|`--css_file` |The location of a css file to copy to the output folder defined in `output_path`. Default: `./templates/stylesheet.css`|
|
||||||
|
|`--site_title` |The title shown on the main page. |
|
||||||
|
|`--title_all` |If enabled, add the main site title to the HTML Title field on the individual articles. |
|
||||||
|
|`-v` |More output. |
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
- Add support for image folders
|
||||||
|
- Handle files correctly :3
|
||||||
|
- GUI interface?
|
||||||
|
|
|
@ -25,6 +25,7 @@ titles = []
|
||||||
|
|
||||||
for rootDir, dirs, files in os.walk(args.input_path):
|
for rootDir, dirs, files in os.walk(args.input_path):
|
||||||
for article in files:
|
for article in files:
|
||||||
|
if not article.endswith(".md"): continue
|
||||||
articles.append(article)
|
articles.append(article)
|
||||||
|
|
||||||
print("\nDiscovering articles...\n")
|
print("\nDiscovering articles...\n")
|
||||||
|
@ -54,7 +55,7 @@ for article in articles:
|
||||||
if parser.getMetadata(article)['draft'] == True:
|
if parser.getMetadata(article)['draft'] == True:
|
||||||
if args.verbose: print('{} is a draft, skipping...'.format(article))
|
if args.verbose: print('{} is a draft, skipping...'.format(article))
|
||||||
continue
|
continue
|
||||||
html = bs(htmls[article]).prettify()
|
html = bs(htmls[article], features="lxml").prettify()
|
||||||
if not os.path.exists(workingDir):
|
if not os.path.exists(workingDir):
|
||||||
os.makedirs(workingDir)
|
os.makedirs(workingDir)
|
||||||
if args.verbose: print("creating directory {}".format(workingDir))
|
if args.verbose: print("creating directory {}".format(workingDir))
|
||||||
|
@ -80,7 +81,7 @@ for article in sorted_articles:
|
||||||
link = article.split("/")[-1][:-3]
|
link = article.split("/")[-1][:-3]
|
||||||
titles.append([title, link])
|
titles.append([title, link])
|
||||||
if args.verbose: print("added {} to titles list with link {}".format(title, link))
|
if args.verbose: print("added {} to titles list with link {}".format(title, link))
|
||||||
mainPage = bs(stitcher.createMainPage(titles, args.template_path, args.site_title)).prettify()
|
mainPage = bs(stitcher.createMainPage(titles, args.template_path, args.site_title), features="lxml").prettify()
|
||||||
print("Generated main page")
|
print("Generated main page")
|
||||||
print("Writing main page to {}".format(args.output_path))
|
print("Writing main page to {}".format(args.output_path))
|
||||||
open(args.output_path + "index.html", 'w').write(mainPage)
|
open(args.output_path + "index.html", 'w').write(mainPage)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue