Skip to content

Commit c04c467

Browse files
Antoine BoelAntoine Boel
authored andcommitted
Do pelican quickstart
1 parent 0811691 commit c04c467

File tree

4 files changed

+295
-0
lines changed

4 files changed

+295
-0
lines changed

Makefile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
PY?=
2+
PELICAN?=pelican
3+
PELICANOPTS=
4+
5+
BASEDIR=$(CURDIR)
6+
INPUTDIR=$(BASEDIR)/content
7+
OUTPUTDIR=$(BASEDIR)/output
8+
CONFFILE=$(BASEDIR)/pelicanconf.py
9+
PUBLISHCONF=$(BASEDIR)/publishconf.py
10+
11+
GITHUB_PAGES_BRANCH=main
12+
GITHUB_PAGES_COMMIT_MESSAGE=Generate Pelican site
13+
14+
15+
DEBUG ?= 0
16+
ifeq ($(DEBUG), 1)
17+
PELICANOPTS += -D
18+
endif
19+
20+
RELATIVE ?= 0
21+
ifeq ($(RELATIVE), 1)
22+
PELICANOPTS += --relative-urls
23+
endif
24+
25+
SERVER ?= "0.0.0.0"
26+
27+
PORT ?= 0
28+
ifneq ($(PORT), 0)
29+
PELICANOPTS += -p $(PORT)
30+
endif
31+
32+
33+
help:
34+
@echo 'Makefile for a pelican Web site '
35+
@echo ' '
36+
@echo 'Usage: '
37+
@echo ' make html (re)generate the web site '
38+
@echo ' make clean remove the generated files '
39+
@echo ' make regenerate regenerate files upon modification '
40+
@echo ' make publish generate using production settings '
41+
@echo ' make serve [PORT=8000] serve site at http://localhost:8000'
42+
@echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
43+
@echo ' make devserver [PORT=8000] serve and regenerate together '
44+
@echo ' make devserver-global regenerate and serve on 0.0.0.0 '
45+
@echo ' make github upload the web site via gh-pages '
46+
@echo ' '
47+
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
48+
@echo 'Set the RELATIVE variable to 1 to enable relative urls '
49+
@echo ' '
50+
51+
html:
52+
"$(PELICAN)" "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
53+
54+
clean:
55+
[ ! -d "$(OUTPUTDIR)" ] || rm -rf "$(OUTPUTDIR)"
56+
57+
regenerate:
58+
"$(PELICAN)" -r "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
59+
60+
serve:
61+
"$(PELICAN)" -l "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
62+
63+
serve-global:
64+
"$(PELICAN)" -l "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS) -b $(SERVER)
65+
66+
devserver:
67+
"$(PELICAN)" -lr "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
68+
69+
devserver-global:
70+
"$(PELICAN)" -lr "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS) -b 0.0.0.0
71+
72+
publish:
73+
"$(PELICAN)" "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(PUBLISHCONF)" $(PELICANOPTS)
74+
75+
github: publish
76+
ghp-import -m "$(GITHUB_PAGES_COMMIT_MESSAGE)" -b $(GITHUB_PAGES_BRANCH) "$(OUTPUTDIR)" --no-jekyll
77+
git push origin $(GITHUB_PAGES_BRANCH)
78+
79+
80+
.PHONY: html help clean regenerate serve serve-global devserver devserver-global publish github

pelicanconf.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
AUTHOR = 'Antoine Boellinger'
2+
SITENAME = 'Antoine Boellinger - Animation Pipeline Consultant'
3+
SITEURL = ""
4+
5+
PATH = "content"
6+
7+
TIMEZONE = 'Europe/Madrid'
8+
9+
DEFAULT_LANG = 'en'
10+
11+
# Feed generation is usually not desired when developing
12+
FEED_ALL_ATOM = None
13+
CATEGORY_FEED_ATOM = None
14+
TRANSLATION_FEED_ATOM = None
15+
AUTHOR_FEED_ATOM = None
16+
AUTHOR_FEED_RSS = None
17+
18+
# Blogroll
19+
LINKS = (
20+
("Pelican", "https://getpelican.com/"),
21+
("Python.org", "https://www.python.org/"),
22+
("Jinja2", "https://palletsprojects.com/p/jinja/"),
23+
("You can modify those links in your config file", "#"),
24+
)
25+
26+
# Social widget
27+
SOCIAL = (
28+
("You can add links in your config file", "#"),
29+
("Another social link", "#"),
30+
)
31+
32+
DEFAULT_PAGINATION = 10
33+
34+
# Uncomment following line if you want document-relative URLs when developing
35+
# RELATIVE_URLS = True

publishconf.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is only used if you use `make publish` or
2+
# explicitly specify it as your config file.
3+
4+
import os
5+
import sys
6+
7+
sys.path.append(os.curdir)
8+
from pelicanconf import *
9+
10+
# If your site is available via HTTPS, make sure SITEURL begins with https://
11+
SITEURL = "https://aboellinger.github.io"
12+
RELATIVE_URLS = False
13+
14+
FEED_ALL_ATOM = "feeds/all.atom.xml"
15+
CATEGORY_FEED_ATOM = "feeds/{slug}.atom.xml"
16+
17+
DELETE_OUTPUT_DIRECTORY = True
18+
19+
# Following items are often useful when publishing
20+
21+
# DISQUS_SITENAME = ""
22+
# GOOGLE_ANALYTICS = ""

tasks.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import os
2+
import shlex
3+
import shutil
4+
import sys
5+
import datetime
6+
7+
from invoke import task
8+
from invoke.main import program
9+
from pelican import main as pelican_main
10+
from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
11+
from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
12+
13+
OPEN_BROWSER_ON_SERVE = True
14+
SETTINGS_FILE_BASE = "pelicanconf.py"
15+
SETTINGS = {}
16+
SETTINGS.update(DEFAULT_CONFIG)
17+
LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
18+
SETTINGS.update(LOCAL_SETTINGS)
19+
20+
CONFIG = {
21+
"settings_base": SETTINGS_FILE_BASE,
22+
"settings_publish": "publishconf.py",
23+
# Output path. Can be absolute or relative to tasks.py. Default: 'output'
24+
"deploy_path": SETTINGS["OUTPUT_PATH"],
25+
# Github Pages configuration
26+
"github_pages_branch": "main",
27+
"commit_message": f"'Publish site on {datetime.date.today().isoformat()}'",
28+
# Host and port for `serve`
29+
"host": "localhost",
30+
"port": 8000,
31+
}
32+
33+
34+
@task
35+
def clean(c):
36+
"""Remove generated files"""
37+
if os.path.isdir(CONFIG["deploy_path"]):
38+
shutil.rmtree(CONFIG["deploy_path"])
39+
os.makedirs(CONFIG["deploy_path"])
40+
41+
42+
@task
43+
def build(c):
44+
"""Build local version of site"""
45+
pelican_run("-s {settings_base}".format(**CONFIG))
46+
47+
48+
@task
49+
def rebuild(c):
50+
"""`build` with the delete switch"""
51+
pelican_run("-d -s {settings_base}".format(**CONFIG))
52+
53+
54+
@task
55+
def regenerate(c):
56+
"""Automatically regenerate site upon file modification"""
57+
pelican_run("-r -s {settings_base}".format(**CONFIG))
58+
59+
60+
@task
61+
def serve(c):
62+
"""Serve site at http://$HOST:$PORT/ (default is localhost:8000)"""
63+
64+
class AddressReuseTCPServer(RootedHTTPServer):
65+
allow_reuse_address = True
66+
67+
server = AddressReuseTCPServer(
68+
CONFIG["deploy_path"],
69+
(CONFIG["host"], CONFIG["port"]),
70+
ComplexHTTPRequestHandler,
71+
)
72+
73+
if OPEN_BROWSER_ON_SERVE:
74+
# Open site in default browser
75+
import webbrowser
76+
77+
webbrowser.open("http://{host}:{port}".format(**CONFIG))
78+
79+
sys.stderr.write("Serving at {host}:{port} ...\n".format(**CONFIG))
80+
server.serve_forever()
81+
82+
83+
@task
84+
def reserve(c):
85+
"""`build`, then `serve`"""
86+
build(c)
87+
serve(c)
88+
89+
90+
@task
91+
def preview(c):
92+
"""Build production version of site"""
93+
pelican_run("-s {settings_publish}".format(**CONFIG))
94+
95+
@task
96+
def livereload(c):
97+
"""Automatically reload browser tab upon file modification."""
98+
from livereload import Server
99+
100+
def cached_build():
101+
cmd = "-s {settings_base} -e CACHE_CONTENT=true LOAD_CONTENT_CACHE=true"
102+
pelican_run(cmd.format(**CONFIG))
103+
104+
cached_build()
105+
server = Server()
106+
theme_path = SETTINGS["THEME"]
107+
watched_globs = [
108+
CONFIG["settings_base"],
109+
f"{theme_path}/templates/**/*.html",
110+
]
111+
112+
content_file_extensions = [".md", ".rst"]
113+
for extension in content_file_extensions:
114+
content_glob = "{}/**/*{}".format(SETTINGS["PATH"], extension)
115+
watched_globs.append(content_glob)
116+
117+
static_file_extensions = [".css", ".js"]
118+
for extension in static_file_extensions:
119+
static_file_glob = f"{theme_path}/static/**/*{extension}"
120+
watched_globs.append(static_file_glob)
121+
122+
for glob in watched_globs:
123+
server.watch(glob, cached_build)
124+
125+
if OPEN_BROWSER_ON_SERVE:
126+
# Open site in default browser
127+
import webbrowser
128+
129+
webbrowser.open("http://{host}:{port}".format(**CONFIG))
130+
131+
server.serve(host=CONFIG["host"], port=CONFIG["port"], root=CONFIG["deploy_path"])
132+
133+
134+
@task
135+
def publish(c):
136+
"""Publish to production via rsync"""
137+
pelican_run("-s {settings_publish}".format(**CONFIG))
138+
c.run(
139+
'rsync --delete --exclude ".DS_Store" -pthrvz -c '
140+
'-e "ssh -p {ssh_port}" '
141+
"{} {ssh_user}@{ssh_host}:{ssh_path}".format(
142+
CONFIG["deploy_path"].rstrip("/") + "/", **CONFIG
143+
)
144+
)
145+
146+
@task
147+
def gh_pages(c):
148+
"""Publish to GitHub Pages"""
149+
preview(c)
150+
c.run(
151+
"ghp-import -b {github_pages_branch} "
152+
"-m {commit_message} "
153+
"{deploy_path} -p".format(**CONFIG)
154+
)
155+
156+
def pelican_run(cmd):
157+
cmd += " " + program.core.remainder # allows to pass-through args to pelican
158+
pelican_main(shlex.split(cmd))

0 commit comments

Comments
 (0)