Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 12a9c39

Browse files
committed
add website framework
1 parent dd4e0ae commit 12a9c39

29 files changed

+1539
-0
lines changed

‎website/.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "plugins/ipynb"]
2+
path = plugins/ipynb
3+
url = git://github.com/danielfrg/pelican-ipynb.git
4+
[submodule "plugins/pelican-plugins"]
5+
path = plugins/pelican-plugins
6+
url = git://github.com/getpelican/pelican-plugins.git

‎website/Makefile

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
PY?=python3
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+
FTP_HOST=localhost
12+
FTP_USER=anonymous
13+
FTP_TARGET_DIR=/
14+
15+
SSH_HOST=localhost
16+
SSH_PORT=22
17+
SSH_USER=root
18+
SSH_TARGET_DIR=/var/www
19+
20+
S3_BUCKET=my_s3_bucket
21+
22+
CLOUDFILES_USERNAME=my_rackspace_username
23+
CLOUDFILES_API_KEY=my_rackspace_api_key
24+
CLOUDFILES_CONTAINER=my_cloudfiles_container
25+
26+
DROPBOX_DIR=~/Dropbox/Public/
27+
28+
GITHUB_PAGES_REMOTE=git@github.com:jakevdp/jakevdp.github.io.git
29+
GITHUB_PAGES_BRANCH=master
30+
31+
GIT_COMMIT_HASH = $(shell git rev-parse HEAD)
32+
33+
DEBUG ?= 0
34+
ifeq ($(DEBUG), 1)
35+
PELICANOPTS += -D
36+
endif
37+
38+
RELATIVE ?= 0
39+
ifeq ($(RELATIVE), 1)
40+
PELICANOPTS += --relative-urls
41+
endif
42+
43+
44+
help:
45+
@echo 'Makefile for a pelican Web site '
46+
@echo ' '
47+
@echo 'Usage: '
48+
@echo ' make html (re)generate the web site '
49+
@echo ' make clean remove the generated files '
50+
@echo ' make regenerate regenerate files upon modification '
51+
@echo ' make publish generate using production settings '
52+
@echo ' make serve [PORT=8000] serve site at http://localhost:8000'
53+
@echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
54+
@echo ' make devserver [PORT=8000] start/restart develop_server.sh '
55+
@echo ' make stopserver stop local server '
56+
@echo ' make ssh_upload upload the web site via SSH '
57+
@echo ' make rsync_upload upload the web site via rsync+ssh '
58+
@echo ' make dropbox_upload upload the web site via Dropbox '
59+
@echo ' make ftp_upload upload the web site via FTP '
60+
@echo ' make s3_upload upload the web site via S3 '
61+
@echo ' make cf_upload upload the web site via Cloud Files'
62+
@echo ' make github upload the web site via gh-pages '
63+
@echo ' '
64+
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
65+
@echo 'Set the RELATIVE variable to 1 to enable relative urls '
66+
@echo ' '
67+
68+
html:
69+
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
70+
71+
clean:
72+
[ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)
73+
74+
regenerate:
75+
$(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
76+
77+
serve:
78+
ifdef PORT
79+
cd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT)
80+
else
81+
cd $(OUTPUTDIR) && $(PY) -m pelican.server
82+
endif
83+
84+
serve-global:
85+
ifdef SERVER
86+
cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER)
87+
else
88+
cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0
89+
endif
90+
91+
92+
devserver:
93+
ifdef PORT
94+
$(BASEDIR)/develop_server.sh restart $(PORT)
95+
else
96+
$(BASEDIR)/develop_server.sh restart
97+
endif
98+
99+
stopserver:
100+
$(BASEDIR)/develop_server.sh stop
101+
@echo 'Stopped Pelican and SimpleHTTPServer processes running in background.'
102+
103+
publish:
104+
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)
105+
106+
ssh_upload: publish
107+
scp -P $(SSH_PORT) -r $(OUTPUTDIR)/* $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)
108+
109+
rsync_upload: publish
110+
rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude
111+
112+
dropbox_upload: publish
113+
cp -r $(OUTPUTDIR)/* $(DROPBOX_DIR)
114+
115+
ftp_upload: publish
116+
lftp ftp://$(FTP_USER)@$(FTP_HOST) -e "mirror -R $(OUTPUTDIR) $(FTP_TARGET_DIR) ; quit"
117+
118+
s3_upload: publish
119+
s3cmd sync $(OUTPUTDIR)/ s3://$(S3_BUCKET) --acl-public --delete-removed --guess-mime-type --no-mime-magic --no-preserve
120+
121+
cf_upload: publish
122+
cd $(OUTPUTDIR) && swift -v -A https://auth.api.rackspacecloud.com/v1.0 -U $(CLOUDFILES_USERNAME) -K $(CLOUDFILES_API_KEY) upload -c $(CLOUDFILES_CONTAINER) .
123+
124+
publish-to-github: publish
125+
ghp-import -n -m "publish-to-github from $(GIT_COMMIT_HASH)" -b blog-build $(OUTPUTDIR)
126+
git push $(GITHUB_PAGES_REMOTE) blog-build:$(GITHUB_PAGES_BRANCH)
127+
128+
publish-to-github-force: publish
129+
ghp-import -n -m "publish-to-github-force from $(GIT_COMMIT_HASH)" -b blog-build $(OUTPUTDIR)
130+
git push -f $(GITHUB_PAGES_REMOTE) blog-build:$(GITHUB_PAGES_BRANCH)
131+
132+
.PHONY: html help clean regenerate serve serve-global devserver stopserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github
134 KB
Loading[フレーム]
93.6 KB
Loading[フレーム]
6.25 KB
Loading[フレーム]

‎website/content/images/jake.jpg

4.98 KB
Loading[フレーム]

‎website/copy_notebooks.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
This script copies all notebooks from the book into the website directory, and
3+
creates pages which wrap them and link together.
4+
"""
5+
import os
6+
import nbformat
7+
8+
PAGEFILE = """title: {title}
9+
slug: {slug}
10+
Template: page
11+
12+
{{% notebook notebooks/{notebook_file} cells[2:] %}}
13+
"""
14+
15+
16+
def abspath_from_here(*args):
17+
here = os.path.dirname(__file__)
18+
path = os.path.join(here, *args)
19+
return os.path.abspath(path)
20+
21+
NB_SOURCE_DIR = abspath_from_here('..', 'notebooks')
22+
NB_DEST_DIR = abspath_from_here('content', 'notebooks')
23+
PAGE_DEST_DIR = abspath_from_here('content', 'pages')
24+
25+
26+
def copy_notebooks():
27+
nblist = sorted(os.listdir(NB_SOURCE_DIR))
28+
name_map = {nb: nb.rsplit('.', 1)[0] + '.html'
29+
for nb in nblist}
30+
31+
for nb in nblist:
32+
base, ext = os.path.splitext(nb)
33+
if ext != '.ipynb':
34+
continue
35+
print('-', nb)
36+
37+
content = nbformat.read(os.path.join(NB_SOURCE_DIR, nb),
38+
as_version=4)
39+
title = content.cells[2].source
40+
if not title.startswith('#'):
41+
raise ValueError('title not found in third cell')
42+
title = title.lstrip('#').strip()
43+
44+
# put nav below title
45+
content.cells[1], content.cells[2] = content.cells[2], content.cells[1]
46+
47+
for cell in content.cells:
48+
if cell.cell_type == 'markdown':
49+
for nbname, htmlname in name_map.items():
50+
if nbname in cell.source:
51+
cell.source = cell.source.replace(nbname, htmlname)
52+
nbformat.write(content, os.path.join(NB_DEST_DIR, nb))
53+
54+
pagefile = os.path.join(PAGE_DEST_DIR, base + '.md')
55+
with open(pagefile, 'w') as f:
56+
f.write(PAGEFILE.format(title=title,
57+
slug=base.lower(),
58+
notebook_file=nb))
59+
60+
if __name__ == '__main__':
61+
copy_notebooks()
62+
63+

‎website/fabfile.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from fabric.api import *
2+
import fabric.contrib.project as project
3+
import os
4+
import shutil
5+
import sys
6+
import SocketServer
7+
8+
from pelican.server import ComplexHTTPRequestHandler
9+
10+
# Local path configuration (can be absolute or relative to fabfile)
11+
env.deploy_path = 'output'
12+
DEPLOY_PATH = env.deploy_path
13+
14+
# Remote server configuration
15+
production = 'root@localhost:22'
16+
dest_path = '/var/www'
17+
18+
# Rackspace Cloud Files configuration settings
19+
env.cloudfiles_username = 'my_rackspace_username'
20+
env.cloudfiles_api_key = 'my_rackspace_api_key'
21+
env.cloudfiles_container = 'my_cloudfiles_container'
22+
23+
# Github Pages configuration
24+
env.github_pages_branch = "master"
25+
26+
# Port for `serve`
27+
PORT = 8000
28+
29+
def clean():
30+
"""Remove generated files"""
31+
if os.path.isdir(DEPLOY_PATH):
32+
shutil.rmtree(DEPLOY_PATH)
33+
os.makedirs(DEPLOY_PATH)
34+
35+
def build():
36+
"""Build local version of site"""
37+
local('pelican -s pelicanconf.py')
38+
39+
def rebuild():
40+
"""`build` with the delete switch"""
41+
local('pelican -d -s pelicanconf.py')
42+
43+
def regenerate():
44+
"""Automatically regenerate site upon file modification"""
45+
local('pelican -r -s pelicanconf.py')
46+
47+
def serve():
48+
"""Serve site at http://localhost:8000/"""
49+
os.chdir(env.deploy_path)
50+
51+
class AddressReuseTCPServer(SocketServer.TCPServer):
52+
allow_reuse_address = True
53+
54+
server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler)
55+
56+
sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
57+
server.serve_forever()
58+
59+
def reserve():
60+
"""`build`, then `serve`"""
61+
build()
62+
serve()
63+
64+
def preview():
65+
"""Build production version of site"""
66+
local('pelican -s publishconf.py')
67+
68+
def cf_upload():
69+
"""Publish to Rackspace Cloud Files"""
70+
rebuild()
71+
with lcd(DEPLOY_PATH):
72+
local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
73+
'-U {cloudfiles_username} '
74+
'-K {cloudfiles_api_key} '
75+
'upload -c {cloudfiles_container} .'.format(**env))
76+
77+
@hosts(production)
78+
def publish():
79+
"""Publish to production via rsync"""
80+
local('pelican -s publishconf.py')
81+
project.rsync_project(
82+
remote_dir=dest_path,
83+
exclude=".DS_Store",
84+
local_dir=DEPLOY_PATH.rstrip('/') + '/',
85+
delete=True,
86+
extra_opts='-c',
87+
)
88+
89+
def gh_pages():
90+
"""Publish to GitHub Pages"""
91+
rebuild()
92+
local("ghp-import -b {github_pages_branch} {deploy_path} -p".format(**env))

‎website/pelicanconf.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*- #
3+
from __future__ import unicode_literals
4+
5+
AUTHOR = 'Jake VanderPlas'
6+
SITENAME = 'Python Data Science Handbook'
7+
SITESUBTITLE = u'Essential Tools for Working with Data'
8+
SITEURL = ''
9+
PATH = 'content'
10+
TIMEZONE = 'America/Los_Angeles'
11+
DEFAULT_LANG = 'en'
12+
13+
# Feed generation is usually not desired when developing
14+
FEED_ALL_ATOM = None
15+
CATEGORY_FEED_ATOM = None
16+
TRANSLATION_FEED_ATOM = None
17+
AUTHOR_FEED_ATOM = None
18+
AUTHOR_FEED_RSS = None
19+
20+
# Set the article URL
21+
ARTICLE_URL = 'blog/{date:%Y}/{date:%m}/{date:%d}/{slug}/'
22+
ARTICLE_SAVE_AS = 'blog/{date:%Y}/{date:%m}/{date:%d}/{slug}/index.html'
23+
24+
DEFAULT_PAGINATION = 10
25+
26+
# Uncomment following line if you want document-relative URLs when developing
27+
#RELATIVE_URLS = True
28+
29+
#MARKUP = ('md', 'ipynb')
30+
#PLUGINS = ['ipynb.markup']
31+
32+
MARKUP = ['md']
33+
PLUGIN_PATHS = ['./plugins', './plugins/pelican-plugins']
34+
PLUGINS = [
35+
'summary', # auto-summarizing articles
36+
'feed_summary', # use summaries for RSS, not full articles
37+
'ipynb.liquid', # for embedding notebooks
38+
'liquid_tags.img', # embedding images
39+
'liquid_tags.video', # embedding videos
40+
'liquid_tags.include_code', # including code blocks
41+
'liquid_tags.literal'
42+
]
43+
IGNORE_FILES = ['.ipynb_checkpoints']
44+
45+
# for liquid tags
46+
CODE_DIR = 'downloads/code'
47+
NOTEBOOK_DIR = 'downloads/notebooks'
48+
49+
# THEME SETTINGS
50+
THEME = './theme/'
51+
52+
ABOUT_PAGE = '/pages/about.html'
53+
TWITTER_USERNAME = 'jakevdp'
54+
GITHUB_USERNAME = 'jakevdp'
55+
STACKOVERFLOW_ADDRESS = 'http://stackoverflow.com/users/2937831/jakevdp'
56+
AUTHOR_WEBSITE = 'http://vanderplas.com'
57+
AUTHOR_CV = "http://staff.washington.edu/jakevdp/media/pdfs/CV.pdf"
58+
SHOW_ARCHIVES = True
59+
SHOW_FEED = False # Need to address large feeds
60+
61+
ENABLE_MATHJAX = True
62+
63+
STATIC_PATHS = ['images', 'figures', 'videos', 'downloads', 'favicon.ico']
64+
65+
# Footer info
66+
67+
LICENSE_URL = "https://github.com/jakevdp/jakevdp.github.io-source/blob/master/LICENSE"
68+
LICENSE = "MIT"

‎website/publishconf.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*- #
3+
from __future__ import unicode_literals
4+
5+
# This file is only used if you use `make publish` or
6+
# explicitly specify it as your config file.
7+
8+
import os
9+
import sys
10+
sys.path.append(os.curdir)
11+
from pelicanconf import *
12+
13+
SITEURL = 'http://jakevdp.github.io'
14+
RELATIVE_URLS = False
15+
16+
SHOW_FEED = True
17+
FEED_ALL_ATOM = 'feeds/all.atom.xml'
18+
CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
19+
FEED_USE_SUMMARY = True # from the feed_summary plugin
20+
21+
DELETE_OUTPUT_DIRECTORY = True
22+
23+
DISQUS_SITENAME = "pythonicperambulations"
24+
GOOGLE_ANALYTICS = "UA-34061646-1"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /