2011-08-19 23:01:01 +02:00
Tips
####
2012-03-06 06:13:17 -08:00
Here are some tips about Pelican that you might find useful.
2011-08-19 23:01:01 +02:00
2015-01-11 18:54:15 -08:00
Custom 404 Pages
================
When a browser requests a resource that the web server cannot find, the web
server usually displays a generic "File not found" (404) error page that can be
2018-11-02 20:53:15 -06:00
stark and unsightly. One way to provide an error page that matches the theme of
your site is to create a custom 404 page (*not* an article), such as this
2016-09-15 06:55:25 -06:00
Markdown-formatted example stored in `` content/pages/404.md `` ::
2015-01-11 18:54:15 -08:00
Title: Not Found
Status: hidden
Save_as: 404.html
The requested item could not be located. Perhaps you might want to check
the [Archives](/archives.html)?
The next step is to configure your web server to display this custom page
instead of its default 404 page. For Nginx, add the following to your
configuration file's `` location `` block::
error_page 404 /404.html;
For Apache::
ErrorDocument 404 /404.html
2016-09-15 06:55:25 -06:00
2018-11-02 20:53:15 -06:00
For Amazon S3, first navigate to the `` Static Site Hosting `` menu in the bucket
2022-07-24 07:55:18 +10:00
settings on your AWS console. From there::
2015-06-19 14:50:12 -04:00
Error Document: 404.html
2015-01-11 18:54:15 -08:00
2023-08-28 19:21:03 +01:00
Publishing to GitHub Pages
==========================
If you use `GitHub <https://github.com/> `_ for your Pelican site you can
publish your site to `GitHub Pages <https://pages.github.com/> `_ for free.
Your site will be published to `` https://<username>.github.io `` if it's a user or
organization site or to `` https://<username>.github.io/<repository> `` if it's a
project site. It's also possible to `use a custom domain with GitHub Pages <https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site> `_ .
There are `two ways to publish a site to GitHub Pages <https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site> `_ :
1. **Publishing from a branch:** run `` pelican `` locally and push the output
directory to a special branch of your GitHub repo. GitHub will then publish
the contents of this branch to your GitHub Pages site.
2. **Publishing with a custom GitHub Actions workflow:** just push the source
files of your Pelican site to your GitHub repo's default branch and have a
custom GitHub Actions workflow run `` pelican `` for you to generate the
output directory and publish it to your GitHub Pages site. This way you
don't need to run `` pelican `` locally. You can even edit your site's source
files using GitHub's web interface and any changes that you commit will be
published.
Publishing a Project Site to GitHub Pages from a Branch
-------------------------------------------------------
2013-01-01 00:36:08 +01:00
2013-09-23 19:30:51 +02:00
To publish a Pelican site as a Project Page you need to *push* the content of
2013-01-01 00:36:08 +01:00
the `` output `` dir generated by Pelican to a repository's `` gh-pages `` branch
on GitHub.
The excellent `ghp-import <https://github.com/davisp/ghp-import> `_ , which can
2015-06-15 07:08:05 -07:00
be installed with `` pip `` , makes this process really easy.
2013-01-01 00:36:08 +01:00
2013-09-23 19:30:51 +02:00
For example, if the source of your Pelican site is contained in a GitHub
repository, and if you want to publish that Pelican site in the form of Project
Pages to this repository, you can then use the following::
2013-01-01 00:36:08 +01:00
2013-06-25 19:17:40 -07:00
$ pelican content -o output -s pelicanconf.py
2018-07-29 19:26:03 -03:00
$ ghp-import output -b gh-pages
2013-01-01 00:36:08 +01:00
$ git push origin gh-pages
The `` ghp-import output `` command updates the local `` gh-pages `` branch with
the content of the `` output `` directory (creating the branch if it doesn't
already exist). The `` git push origin gh-pages `` command updates the remote
`` gh-pages `` branch, effectively publishing the Pelican site.
.. note ::
2018-11-02 20:53:15 -06:00
The `` github `` target of the Makefile (and the `` gh_pages `` task of
`` tasks.py `` ) created by the `` pelican-quickstart `` command publishes the
Pelican site as Project Pages, as described above.
2013-01-01 00:36:08 +01:00
2023-08-28 19:21:03 +01:00
Publishing a User Site to GitHub Pages from a Branch
----------------------------------------------------
2012-06-10 00:00:49 +05:30
2013-09-23 19:30:51 +02:00
To publish a Pelican site in the form of User Pages, you need to *push* the
content of the `` output `` dir generated by Pelican to the `` master `` branch of
your `` <username>.github.io `` repository on GitHub.
2012-06-10 00:00:49 +05:30
2013-01-01 00:36:08 +01:00
Again, you can take advantage of `` ghp-import `` ::
2012-06-10 00:00:49 +05:30
2013-06-26 06:39:09 -07:00
$ pelican content -o output -s pelicanconf.py
2018-07-29 19:26:03 -03:00
$ ghp-import output -b gh-pages
2013-09-23 19:30:51 +02:00
$ git push git@github.com:elemoine/elemoine.github.io.git gh-pages:master
2012-06-10 00:00:49 +05:30
2013-01-01 00:36:08 +01:00
The `` git push `` command pushes the local `` gh-pages `` branch (freshly updated
2013-09-23 19:30:51 +02:00
by the `` ghp-import `` command) to the `` elemoine.github.io `` repository's
2013-01-01 00:36:08 +01:00
`` master `` branch on GitHub.
2012-06-10 00:00:49 +05:30
2013-01-01 00:36:08 +01:00
.. note ::
2011-08-19 23:01:01 +02:00
2013-09-23 19:30:51 +02:00
To publish your Pelican site as User Pages, feel free to adjust the
2013-01-01 00:36:08 +01:00
`` github `` target of the Makefile.
2021-07-09 08:28:15 -06:00
2018-11-02 20:53:15 -06:00
Another option for publishing to User Pages is to generate the output files in
the root directory of the project.
2017-04-28 19:18:44 -07:00
2018-11-02 20:53:15 -06:00
For example, your main project folder is `` <username>.github.io `` and you can
create the Pelican project in a subdirectory called `` Pelican `` . Then from
inside the `` Pelican `` folder you can run::
2021-07-09 08:28:15 -06:00
2017-04-28 19:18:44 -07:00
$ pelican content -o .. -s pelicanconf.py
2018-11-02 20:53:15 -06:00
Now you can push the whole project `` <username>.github.io `` to the master
branch of your GitHub repository::
2021-07-09 08:28:15 -06:00
2017-04-28 19:18:44 -07:00
$ git push origin master
2021-07-09 08:28:15 -06:00
2017-04-28 19:18:44 -07:00
(assuming origin is set to your remote repository).
2011-08-19 23:01:01 +02:00
2023-08-28 19:21:03 +01:00
Publishing to GitHub Pages Using a Custom GitHub Actions Workflow
-----------------------------------------------------------------
2024-05-29 07:28:22 +02:00
Pelican-powered sites can be published to GitHub Pages via a `custom workflow
<https://github.com/getpelican/pelican/blob/master/.github/workflows/github_pages.yml> `_.
**No official support is provided** for this community-submitted workflow. To use it:
2023-08-28 19:21:03 +01:00
1. Enable GitHub Pages in your repo: go to **Settings → Pages** and choose
**GitHub Actions** for the **Source** setting.
2. Commit a `` .github/workflows/pelican.yml `` file to your repo with these contents:
.. code-block :: yaml
name: Deploy to GitHub Pages
on:
push:
branches: ["main"]
workflow_dispatch:
jobs:
deploy:
uses: "getpelican/pelican/.github/workflows/github_pages.yml@master"
permissions:
contents: "read"
pages: "write"
id-token: "write"
with:
settings: "publishconf.py"
3. Go to the **Actions** tab in your repo
(`` https://github.com/<username>/<repository>/actions `` ) and you should see a
**Deploy to GitHub Pages** action running.
4. Once the action completes you should see your Pelican site deployed at your
repo's GitHub Pages URL: `` https://<username>.github.io `` for a user or
organization site or `` https://<username>.github.io/<repository>> `` for a
project site.
Notes:
* You don't need to set `` SITEURL `` in your Pelican settings: the workflow will
set it for you
* You don't need to commit your `` --output `` / `` OUTPUT_PATH `` directory
(`` output/ `` ) to git: the workflow will run `` pelican `` to build the output
directory for you on GitHub Actions
See `GitHub's docs about reusable workflows <https://docs.github.com/en/actions/using-workflows/reusing-workflows> `_
for more information.
A number of optional inputs can be added to the `` with: `` block when calling
the workflow:
+--------------+----------+-----------------------------------+--------+---------------+
| Name | Required | Description | Type | Default |
+==============+==========+===================================+========+===============+
| settings | Yes | The path to your Pelican settings | string | |
| | | file (`` pelican `` 's | | |
| | | `` --settings `` option), | | |
| | | for example: `` "publishconf.py" `` | | |
+--------------+----------+-----------------------------------+--------+---------------+
| requirements | No | The Python requirements to | string | `` "pelican" `` |
| | | install, for example to enable | | |
| | | markdown and typogrify use: | | |
| | | `` "pelican[markdown] typogrify" `` | | |
2023-10-29 18:30:25 +03:00
| | | or if you have a requirements | | |
| | | file: `` "-r requirements.txt" `` | | |
2023-08-28 19:21:03 +01:00
+--------------+----------+-----------------------------------+--------+---------------+
| output-path | No | Where to output the generated | string | `` "output/" `` |
| | | files (`` pelican `` 's `` --output `` | | |
| | | option) | | |
+--------------+----------+-----------------------------------+--------+---------------+
For example:
.. code-block :: yaml
with:
settings: "publishconf.py"
requirements: "pelican[markdown] typogrify"
output-path: "__output__/"
2015-01-10 00:31:01 +05:30
Custom 404 Pages
----------------
GitHub Pages will display the custom 404 page described above, as noted in the
relevant `GitHub docs <https://help.github.com/articles/custom-404-pages/> `_ .
2017-01-14 13:51:10 +01:00
Update your site on each commit
-------------------------------
2013-01-01 00:36:08 +01:00
2018-11-02 20:53:15 -06:00
To automatically update your Pelican site on each commit, you can create a
post-commit hook. For example, you can add the following to
2013-01-01 00:36:08 +01:00
`` .git/hooks/post-commit `` ::
2011-08-19 23:01:01 +02:00
2013-09-23 19:30:51 +02:00
pelican content -o output -s pelicanconf.py && ghp-import output && git push origin gh-pages
2011-08-19 23:01:01 +02:00
2017-01-14 13:51:10 +01:00
Copy static files to the root of your site
------------------------------------------
2011-08-19 23:01:01 +02:00
2013-01-01 00:36:08 +01:00
To use a `custom domain
<https://help.github.com/articles/setting-up-a-custom-domain-with-pages> `_ with
2013-09-23 19:30:51 +02:00
GitHub Pages, you need to put the domain of your site (e.g.,
`` blog.example.com `` ) inside a `` CNAME `` file at the root of your site. To do
2013-11-19 16:49:37 +05:30
this, create the `` content/extra/ `` directory and add a `` CNAME `` file to it.
2013-09-23 19:30:51 +02:00
Then use the `` STATIC_PATHS `` setting to tell Pelican to copy this file to your
output directory. For example::
2012-06-10 00:00:49 +05:30
2013-09-23 19:30:51 +02:00
STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
2013-09-09 00:52:26 +05:00
2015-01-02 23:45:44 -08:00
Note: use forward slashes, `` / `` , even on Windows.
2018-11-02 20:53:15 -06:00
You can also use the `` EXTRA_PATH_METADATA `` mechanism to place a
`` favicon.ico `` or `` robots.txt `` at the root of any site.
2015-01-02 23:45:44 -08:00
2013-09-23 19:30:51 +02:00
How to add YouTube or Vimeo Videos
2013-09-09 00:52:26 +05:00
==================================
2013-09-23 19:30:51 +02:00
The easiest way is to paste the embed code of the video from these sites
directly into your source content.
2013-09-09 00:52:26 +05:00
2013-09-23 19:30:51 +02:00
Alternatively, you can also use Pelican plugins like `` liquid_tags `` ,
`` pelican_youtube `` , or `` pelican_vimeo `` to embed videos in your content.
2013-10-21 23:38:25 +02:00
Moreover, markup languages like reST and Markdown have plugins that let you
embed videos in the markup. You can use `reST video directive
<https://gist.github.com/dbrgn/2922648> `_ for reST or ` mdx_video plugin
<https://github.com/italomaia/mdx-video> `_ for Markdown.
2015-01-10 00:31:01 +05:30
2017-12-26 16:36:45 -08:00
Develop Locally Using SSL
==================================
Here's how you can set up your local pelican server to support SSL.
First, create a self-signed certificate and key using `` openssl `` (this creates `` cert.pem `` and `` key.pem `` )::
$ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
And use this command to launch the server (the server starts within your `` output `` directory)::
python -m pelican.server 8443 --key=../key.pem --cert=../cert.pem
If you are using `` develop-server.sh `` , add this to the top::
CERT="$BASEDIR/cert.pem"
KEY="$BASEDIR/key.pem"
and modify the `` pelican.server `` line as follows::
2021-07-09 08:28:15 -06:00
$PY -m pelican.server $port --ssl --cert="$CERT" --key="$KEY" &