mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix #2888 -- Apply ruff and pyupgrade to templates
This commit is contained in:
parent
903ce3ce33
commit
db241feaa4
3 changed files with 82 additions and 64 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
AUTHOR = {{author}}
|
AUTHOR = {{author}}
|
||||||
SITENAME = {{sitename}}
|
SITENAME = {{sitename}}
|
||||||
SITEURL = ''
|
SITEURL = ""
|
||||||
|
|
||||||
PATH = 'content'
|
PATH = "content"
|
||||||
|
|
||||||
TIMEZONE = {{timezone}}
|
TIMEZONE = {{timezone}}
|
||||||
|
|
||||||
|
|
@ -16,16 +16,20 @@ AUTHOR_FEED_ATOM = None
|
||||||
AUTHOR_FEED_RSS = None
|
AUTHOR_FEED_RSS = None
|
||||||
|
|
||||||
# Blogroll
|
# Blogroll
|
||||||
LINKS = (('Pelican', 'https://getpelican.com/'),
|
LINKS = (
|
||||||
('Python.org', 'https://www.python.org/'),
|
("Pelican", "https://getpelican.com/"),
|
||||||
('Jinja2', 'https://palletsprojects.com/p/jinja/'),
|
("Python.org", "https://www.python.org/"),
|
||||||
('You can modify those links in your config file', '#'),)
|
("Jinja2", "https://palletsprojects.com/p/jinja/"),
|
||||||
|
("You can modify those links in your config file", "#"),
|
||||||
|
)
|
||||||
|
|
||||||
# Social widget
|
# Social widget
|
||||||
SOCIAL = (('You can add links in your config file', '#'),
|
SOCIAL = (
|
||||||
('Another social link', '#'),)
|
("You can add links in your config file", "#"),
|
||||||
|
("Another social link", "#"),
|
||||||
|
)
|
||||||
|
|
||||||
DEFAULT_PAGINATION = {{default_pagination}}
|
DEFAULT_PAGINATION = {{default_pagination}}
|
||||||
|
|
||||||
# Uncomment following line if you want document-relative URLs when developing
|
# Uncomment following line if you want document-relative URLs when developing
|
||||||
#RELATIVE_URLS = True
|
# RELATIVE_URLS = True
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,20 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.append(os.curdir)
|
sys.path.append(os.curdir)
|
||||||
from pelicanconf import *
|
from pelicanconf import *
|
||||||
|
|
||||||
# If your site is available via HTTPS, make sure SITEURL begins with https://
|
# If your site is available via HTTPS, make sure SITEURL begins with https://
|
||||||
SITEURL = '{{siteurl}}'
|
SITEURL = "{{siteurl}}"
|
||||||
RELATIVE_URLS = False
|
RELATIVE_URLS = False
|
||||||
|
|
||||||
FEED_ALL_ATOM = 'feeds/all.atom.xml'
|
FEED_ALL_ATOM = "feeds/all.atom.xml"
|
||||||
CATEGORY_FEED_ATOM = 'feeds/{slug}.atom.xml'
|
CATEGORY_FEED_ATOM = "feeds/{slug}.atom.xml"
|
||||||
|
|
||||||
DELETE_OUTPUT_DIRECTORY = True
|
DELETE_OUTPUT_DIRECTORY = True
|
||||||
|
|
||||||
# Following items are often useful when publishing
|
# Following items are often useful when publishing
|
||||||
|
|
||||||
#DISQUS_SITENAME = ""
|
# DISQUS_SITENAME = ""
|
||||||
#GOOGLE_ANALYTICS = ""
|
# GOOGLE_ANALYTICS = ""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
|
|
@ -14,61 +12,66 @@ from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
|
||||||
from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
|
from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
|
||||||
|
|
||||||
OPEN_BROWSER_ON_SERVE = True
|
OPEN_BROWSER_ON_SERVE = True
|
||||||
SETTINGS_FILE_BASE = 'pelicanconf.py'
|
SETTINGS_FILE_BASE = "pelicanconf.py"
|
||||||
SETTINGS = {}
|
SETTINGS = {}
|
||||||
SETTINGS.update(DEFAULT_CONFIG)
|
SETTINGS.update(DEFAULT_CONFIG)
|
||||||
LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
|
LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
|
||||||
SETTINGS.update(LOCAL_SETTINGS)
|
SETTINGS.update(LOCAL_SETTINGS)
|
||||||
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
'settings_base': SETTINGS_FILE_BASE,
|
"settings_base": SETTINGS_FILE_BASE,
|
||||||
'settings_publish': 'publishconf.py',
|
"settings_publish": "publishconf.py",
|
||||||
# Output path. Can be absolute or relative to tasks.py. Default: 'output'
|
# Output path. Can be absolute or relative to tasks.py. Default: 'output'
|
||||||
'deploy_path': SETTINGS['OUTPUT_PATH'],
|
"deploy_path": SETTINGS["OUTPUT_PATH"],
|
||||||
{% if ssh %}
|
{% if ssh %}
|
||||||
# Remote server configuration
|
# Remote server configuration
|
||||||
'ssh_user': '{{ssh_user}}',
|
"ssh_user": "{{ssh_user}}",
|
||||||
'ssh_host': '{{ssh_host}}',
|
"ssh_host": "{{ssh_host}}",
|
||||||
'ssh_port': '{{ssh_port}}',
|
"ssh_port": "{{ssh_port}}",
|
||||||
'ssh_path': '{{ssh_target_dir}}',
|
"ssh_path": "{{ssh_target_dir}}",
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if cloudfiles %}
|
{% if cloudfiles %}
|
||||||
# Rackspace Cloud Files configuration settings
|
# Rackspace Cloud Files configuration settings
|
||||||
'cloudfiles_username': '{{cloudfiles_username}}',
|
"cloudfiles_username": "{{cloudfiles_username}}",
|
||||||
'cloudfiles_api_key': '{{cloudfiles_api_key}}',
|
"cloudfiles_api_key": "{{cloudfiles_api_key}}",
|
||||||
'cloudfiles_container': '{{cloudfiles_container}}',
|
"cloudfiles_container": "{{cloudfiles_container}}",
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if github %}
|
{% if github %}
|
||||||
# Github Pages configuration
|
# Github Pages configuration
|
||||||
'github_pages_branch': '{{github_pages_branch}}',
|
"github_pages_branch": "{{github_pages_branch}}",
|
||||||
'commit_message': "'Publish site on {}'".format(datetime.date.today().isoformat()),
|
"commit_message": f"'Publish site on {datetime.date.today().isoformat()}'",
|
||||||
{% endif %}
|
{% endif %}
|
||||||
# Host and port for `serve`
|
# Host and port for `serve`
|
||||||
'host': 'localhost',
|
"host": "localhost",
|
||||||
'port': 8000,
|
"port": 8000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def clean(c):
|
def clean(c):
|
||||||
"""Remove generated files"""
|
"""Remove generated files"""
|
||||||
if os.path.isdir(CONFIG['deploy_path']):
|
if os.path.isdir(CONFIG["deploy_path"]):
|
||||||
shutil.rmtree(CONFIG['deploy_path'])
|
shutil.rmtree(CONFIG["deploy_path"])
|
||||||
os.makedirs(CONFIG['deploy_path'])
|
os.makedirs(CONFIG["deploy_path"])
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def build(c):
|
def build(c):
|
||||||
"""Build local version of site"""
|
"""Build local version of site"""
|
||||||
pelican_run('-s {settings_base}'.format(**CONFIG))
|
pelican_run("-s {settings_base}".format(**CONFIG))
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def rebuild(c):
|
def rebuild(c):
|
||||||
"""`build` with the delete switch"""
|
"""`build` with the delete switch"""
|
||||||
pelican_run('-d -s {settings_base}'.format(**CONFIG))
|
pelican_run("-d -s {settings_base}".format(**CONFIG))
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def regenerate(c):
|
def regenerate(c):
|
||||||
"""Automatically regenerate site upon file modification"""
|
"""Automatically regenerate site upon file modification"""
|
||||||
pelican_run('-r -s {settings_base}'.format(**CONFIG))
|
pelican_run("-r -s {settings_base}".format(**CONFIG))
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def serve(c):
|
def serve(c):
|
||||||
|
|
@ -78,28 +81,32 @@ def serve(c):
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
|
|
||||||
server = AddressReuseTCPServer(
|
server = AddressReuseTCPServer(
|
||||||
CONFIG['deploy_path'],
|
CONFIG["deploy_path"],
|
||||||
(CONFIG['host'], CONFIG['port']),
|
(CONFIG["host"], CONFIG["port"]),
|
||||||
ComplexHTTPRequestHandler)
|
ComplexHTTPRequestHandler,
|
||||||
|
)
|
||||||
|
|
||||||
if OPEN_BROWSER_ON_SERVE:
|
if OPEN_BROWSER_ON_SERVE:
|
||||||
# Open site in default browser
|
# Open site in default browser
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
webbrowser.open("http://{host}:{port}".format(**CONFIG))
|
webbrowser.open("http://{host}:{port}".format(**CONFIG))
|
||||||
|
|
||||||
sys.stderr.write('Serving at {host}:{port} ...\n'.format(**CONFIG))
|
sys.stderr.write("Serving at {host}:{port} ...\n".format(**CONFIG))
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def reserve(c):
|
def reserve(c):
|
||||||
"""`build`, then `serve`"""
|
"""`build`, then `serve`"""
|
||||||
build(c)
|
build(c)
|
||||||
serve(c)
|
serve(c)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def preview(c):
|
def preview(c):
|
||||||
"""Build production version of site"""
|
"""Build production version of site"""
|
||||||
pelican_run('-s {settings_publish}'.format(**CONFIG))
|
pelican_run("-s {settings_publish}".format(**CONFIG))
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def livereload(c):
|
def livereload(c):
|
||||||
|
|
@ -107,25 +114,25 @@ def livereload(c):
|
||||||
from livereload import Server
|
from livereload import Server
|
||||||
|
|
||||||
def cached_build():
|
def cached_build():
|
||||||
cmd = '-s {settings_base} -e CACHE_CONTENT=true LOAD_CONTENT_CACHE=true'
|
cmd = "-s {settings_base} -e CACHE_CONTENT=true LOAD_CONTENT_CACHE=true"
|
||||||
pelican_run(cmd.format(**CONFIG))
|
pelican_run(cmd.format(**CONFIG))
|
||||||
|
|
||||||
cached_build()
|
cached_build()
|
||||||
server = Server()
|
server = Server()
|
||||||
theme_path = SETTINGS['THEME']
|
theme_path = SETTINGS["THEME"]
|
||||||
watched_globs = [
|
watched_globs = [
|
||||||
CONFIG['settings_base'],
|
CONFIG["settings_base"],
|
||||||
'{}/templates/**/*.html'.format(theme_path),
|
f"{theme_path}/templates/**/*.html",
|
||||||
]
|
]
|
||||||
|
|
||||||
content_file_extensions = ['.md', '.rst']
|
content_file_extensions = [".md", ".rst"]
|
||||||
for extension in content_file_extensions:
|
for extension in content_file_extensions:
|
||||||
content_glob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
|
content_glob = "{}/**/*{}".format(SETTINGS["PATH"], extension)
|
||||||
watched_globs.append(content_glob)
|
watched_globs.append(content_glob)
|
||||||
|
|
||||||
static_file_extensions = ['.css', '.js']
|
static_file_extensions = [".css", ".js"]
|
||||||
for extension in static_file_extensions:
|
for extension in static_file_extensions:
|
||||||
static_file_glob = '{0}/static/**/*{1}'.format(theme_path, extension)
|
static_file_glob = f"{theme_path}/static/**/*{extension}"
|
||||||
watched_globs.append(static_file_glob)
|
watched_globs.append(static_file_glob)
|
||||||
|
|
||||||
for glob in watched_globs:
|
for glob in watched_globs:
|
||||||
|
|
@ -134,43 +141,49 @@ def livereload(c):
|
||||||
if OPEN_BROWSER_ON_SERVE:
|
if OPEN_BROWSER_ON_SERVE:
|
||||||
# Open site in default browser
|
# Open site in default browser
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
webbrowser.open("http://{host}:{port}".format(**CONFIG))
|
webbrowser.open("http://{host}:{port}".format(**CONFIG))
|
||||||
|
|
||||||
server.serve(host=CONFIG['host'], port=CONFIG['port'], root=CONFIG['deploy_path'])
|
server.serve(host=CONFIG["host"], port=CONFIG["port"], root=CONFIG["deploy_path"])
|
||||||
|
|
||||||
{% if cloudfiles %}
|
{% if cloudfiles %}
|
||||||
@task
|
@task
|
||||||
def cf_upload(c):
|
def cf_upload(c):
|
||||||
"""Publish to Rackspace Cloud Files"""
|
"""Publish to Rackspace Cloud Files"""
|
||||||
rebuild(c)
|
rebuild(c)
|
||||||
with cd(CONFIG['deploy_path']):
|
with cd(CONFIG["deploy_path"]):
|
||||||
c.run('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
|
c.run(
|
||||||
'-U {cloudfiles_username} '
|
"swift -v -A https://auth.api.rackspacecloud.com/v1.0 "
|
||||||
'-K {cloudfiles_api_key} '
|
"-U {cloudfiles_username} "
|
||||||
'upload -c {cloudfiles_container} .'.format(**CONFIG))
|
"-K {cloudfiles_api_key} "
|
||||||
|
"upload -c {cloudfiles_container} .".format(**CONFIG)
|
||||||
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def publish(c):
|
def publish(c):
|
||||||
"""Publish to production via rsync"""
|
"""Publish to production via rsync"""
|
||||||
pelican_run('-s {settings_publish}'.format(**CONFIG))
|
pelican_run("-s {settings_publish}".format(**CONFIG))
|
||||||
c.run(
|
c.run(
|
||||||
'rsync --delete --exclude ".DS_Store" -pthrvz -c '
|
'rsync --delete --exclude ".DS_Store" -pthrvz -c '
|
||||||
'-e "ssh -p {ssh_port}" '
|
'-e "ssh -p {ssh_port}" '
|
||||||
'{} {ssh_user}@{ssh_host}:{ssh_path}'.format(
|
"{} {ssh_user}@{ssh_host}:{ssh_path}".format(
|
||||||
CONFIG['deploy_path'].rstrip('/') + '/',
|
CONFIG["deploy_path"].rstrip("/") + "/", **CONFIG
|
||||||
**CONFIG))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
{% if github %}
|
{% if github %}
|
||||||
@task
|
@task
|
||||||
def gh_pages(c):
|
def gh_pages(c):
|
||||||
"""Publish to GitHub Pages"""
|
"""Publish to GitHub Pages"""
|
||||||
preview(c)
|
preview(c)
|
||||||
c.run('ghp-import -b {github_pages_branch} '
|
c.run(
|
||||||
'-m {commit_message} '
|
"ghp-import -b {github_pages_branch} "
|
||||||
'{deploy_path} -p'.format(**CONFIG))
|
"-m {commit_message} "
|
||||||
|
"{deploy_path} -p".format(**CONFIG)
|
||||||
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
def pelican_run(cmd):
|
def pelican_run(cmd):
|
||||||
cmd += ' ' + program.core.remainder # allows to pass-through args to pelican
|
cmd += " " + program.core.remainder # allows to pass-through args to pelican
|
||||||
pelican_main(shlex.split(cmd))
|
pelican_main(shlex.split(cmd))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue