Skip to content

Commit

Permalink
Update versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Siecje committed Dec 6, 2023
1 parent aca0326 commit e7135a6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ $ venv/bin/python -m pip install -e htmd/
$ mkdir my_site
$ cd my_site
$ ../venv/bin/htmd start
# You can also create a symlink to htmd
# somewhere on your $PATH and just use `htmd start`
$ ../venv/bin/htmd build
```

### Running the tests

```shell
$ git clone https://github.com/Siecje/htmd.git
$ cd htmd
$ python3 -m venv venv
$ venv/bin/python -m pip install pip setuptools wheel --upgrade
$ venv/bin/python -m pip install -e .
$ venv/bin/python -m pip install pytest
$ venv/bin/python -m pytest .
```
Expand Down
62 changes: 37 additions & 25 deletions htmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,49 @@ def start(all_templates):
if all_templates:
copy_missing_templates()
else:
copy_file(
importlib.resources.path('htmd.example_site.templates', '_layout.html'),
os.path.join('templates/', '_layout.html')
)
resource_path = importlib.resources.path('htmd.example_site.templates', '_layout.html')
with resource_path as path:
copy_file(
path,
os.path.join('templates/', '_layout.html')
)

create_directory('static/')
copy_file(
importlib.resources.path('htmd.example_site.static', '_reset.css'),
os.path.join('static/', '_reset.css')
)
copy_file(
importlib.resources.path('htmd.example_site.static', 'style.css'),
os.path.join('static/', 'style.css'),
)
resource_path = importlib.resources.path('htmd.example_site.static', '_reset.css')
with resource_path as path:
copy_file(
path,
os.path.join('static/', '_reset.css')
)
resource_path = importlib.resources.path('htmd.example_site.static', 'style.css')
with resource_path as path:
copy_file(
path,
os.path.join('static/', 'style.css'),
)

create_directory('pages/')
copy_file(
importlib.resources.path('htmd.example_site.pages', 'about.html'),
os.path.join('pages/', 'about.html'),
)
resource_path = importlib.resources.path('htmd.example_site.pages', 'about.html')
with resource_path as path:
copy_file(
path,
os.path.join('pages/', 'about.html'),
)

create_directory('posts/')
copy_file(
importlib.resources.path('htmd.example_site.posts', 'example.md'),
os.path.join('posts/', 'example.md'),
)

copy_file(
importlib.resources.path('htmd.example_site', 'config.py'),
os.path.join('config.py'),
)
resource_path = importlib.resources.path('htmd.example_site.posts', 'example.md')
with resource_path as path:
copy_file(
path,
os.path.join('posts/', 'example.md'),
)

resource_path = importlib.resources.path('htmd.example_site', 'config.py')
with resource_path as path:
copy_file(
path,
'config.py',
)
click.echo('Add the site name and edit settings in config.py')


Expand Down
12 changes: 6 additions & 6 deletions htmd/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def not_found():


@app.route('/<int:year>/')
def year(year):
def year_view(year):
year = str(year)
if len(year) != 4:
abort(404)
Expand All @@ -239,7 +239,7 @@ def year(year):


@app.route('/<year>/<month>/')
def month(year, month):
def month_view(year, month):
month_posts = [
p for p in posts if year == p.meta.get('published').strftime('%Y')
and month == p.meta.get('published').strftime('%m')
Expand All @@ -258,7 +258,7 @@ def month(year, month):


@app.route('/<year>/<month>/<day>/')
def day(year, month, day):
def day_view(year, month, day):
day_posts = [
p for p in posts if year == p.meta.get('published').strftime('%Y')
and month == p.meta.get('published').strftime('%m')
Expand All @@ -283,20 +283,20 @@ def page_not_found(e):

# Telling Frozen-Flask about routes that are not linked to in templates
@freezer.register_generator
def year():
def year_view():
for post in posts:
yield {'year': post.meta.get('published').year}


@freezer.register_generator
def month():
def month_view():
for post in posts:
yield {'year': post.meta.get('published').year,
'month': post.meta.get('published').strftime('%m')}


@freezer.register_generator
def day():
def day_view():
for post in posts:
yield {'year': post.meta.get('published').year,
'month': post.meta.get('published').strftime('%m'),
Expand Down
20 changes: 11 additions & 9 deletions htmd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def create_directory(name):
click.echo(click.style(f'{name} was created.', fg='green'))


def copy_file(src, dest):
if os.path.exists(dest) is False:
shutil.copyfile(src, dest)
click.echo(click.style(f'{dest} was created.', fg='green'))
def copy_file(source, destination):
if os.path.exists(destination) is False:
shutil.copyfile(source, destination)
click.echo(click.style(f'{destination} was created.', fg='green'))
else:
msg = f'{dest} already exists and was not created.'
msg = f'{destination} already exists and was not created.'
click.echo(click.style(msg, fg='red'))


Expand Down Expand Up @@ -83,7 +83,9 @@ def copy_missing_templates():
if template_file in ('__init__.py', '__pycache__'):
# __init__.py is that this directory for importlib.resources to work
continue
copy_file(
importlib.resources.path('htmd.example_site.templates', template_file),
os.path.join('templates', template_file)
)
resource_path = importlib.resources.path('htmd.example_site.templates', template_file)
with resource_path as path:
copy_file(
path,
os.path.join('templates', template_file)
)
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
beautifulsoup4==4.10.0
feedwerk==1.0.0
Flask==2.0.3
Flask-FlatPages==0.8.1
Frozen-Flask==0.18
Pygments==2.11.2
click==8.0.4
beautifulsoup4==4.12.2
feedwerk==1.1.0
Flask==3.0.0
Flask-FlatPages==0.8.2
Frozen-Flask==1.0.1
Pygments==2.17.2
click==8.1.7
htmlmin==0.1.12
jsmin==3.0.1
csscompressor==0.9.5

0 comments on commit e7135a6

Please sign in to comment.