### Install Dependencies and Setup Project Source: https://github.com/getpelican/pelican/blob/main/docs/contribute.rst Installs the Invoke task runner and sets up the Pelican project for local development. ```bash python -m pip install invoke invoke setup ``` -------------------------------- ### Install a Theme (Console) Source: https://github.com/getpelican/pelican/blob/main/docs/pelican-themes.rst Install one or more themes by providing their paths with the -i or --install option. Can be combined with --verbose. ```console # pelican-themes --install ~/Dev/Python/pelican-themes/notmyidea-cms --verbose ``` ```console # pelican-themes --install ~/Dev/Python/pelican-themes/notmyidea-cms\ ~/Dev/Python/pelican-themes/martyalchin \ --verbose ``` ```console # pelican-themes -vi ~/Dev/Python/pelican-themes/two-column ``` -------------------------------- ### Install Pelican from source using setuptools Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Install Pelican from its source code using the setuptools method within a virtual environment. ```bash cd path-to-Pelican-source python3 -m pip install . ``` -------------------------------- ### Install Invoke Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Install the Invoke task execution tool using pip. Use 'sudo' if necessary. ```bash python -m pip install invoke ``` -------------------------------- ### Set up a virtual environment and install Pelican Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Manually create and activate a virtual environment before installing Pelican with Markdown support. ```bash python3 -m venv ~/virtualenvs/pelican source ~/virtualenvs/pelican/bin/activate python3 -m pip install "pelican[markdown]" ``` -------------------------------- ### Serve Site with Invoke Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Use the 'serve' task to start a local web server for previewing your site. ```bash invoke serve ``` -------------------------------- ### Install Pelican with Typogrify using uv Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Install Pelican with Markdown and Typogrify support using the uv command. ```bash uv tool install --with typogrify "pelican[markdown]" ``` -------------------------------- ### Install Pelican with uv Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Install Pelican using uv for isolated environments, including Markdown support. ```bash uv tool install "pelican[markdown]" ``` -------------------------------- ### Project Quickstart with pelican-quickstart Source: https://context7.com/getpelican/pelican/llms.txt Scaffolds a new Pelican project using an interactive wizard. It generates essential configuration files and a Makefile/tasks.py for automation. ```bash mkdir -p ~/projects/myblog cd ~/projects/myblog pelican-quickstart # Prompts for site name, URL, timezone, pagination, etc. # Generates: # pelicanconf.py — development settings # publishconf.py — production settings # Makefile — make-based automation # tasks.py — Invoke-based automation ``` -------------------------------- ### Install Typogrify for typographical enhancements Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Install the Typogrify library using Pip for optional typographical enhancements. ```bash python3 -m pip install --user typogrify ``` -------------------------------- ### Install and Use pelican-import Source: https://context7.com/getpelican/pelican/llms.txt Installs optional dependencies for `pelican-import` and demonstrates various command-line options for importing content from different platforms like WordPress, Blogger, Medium, and RSS feeds. ```bash # Install optional dependencies pip install BeautifulSoup4 lxml feedparser # Import from WordPress XML export → reStructuredText pelican-import --wpfile -o content/ ~/wordpress-export.xml # Import from WordPress, organize by category, also download attachments pelican-import --wpfile --dir-cat --wp-attach -o content/ ~/wordpress-export.xml # Import from Blogger XML export pelican-import --blogger -o content/ ~/blogger-export.xml # Import from Medium export (unzip first, point to posts/ subdirectory) pelican-import --medium -o content/ ~/medium-export/posts/ # Import from a live RSS/Atom feed pelican-import --feed -o content/ https://example.com/feed/ # Import from Tumblr API pelican-import --tumblr -o content/ --blogname=myblog # Output as Markdown instead of the default reStructuredText pelican-import --wpfile -m markdown -o content/ ~/wordpress-export.xml ``` -------------------------------- ### Install Pelican with Markdown Support Source: https://github.com/getpelican/pelican/blob/main/docs/quickstart.rst Use pip to install Pelican and the optional Markdown parser. Ensure you have the correct Python version. ```bash python -m pip install "pelican[markdown]" ``` -------------------------------- ### Install Pelican with Markdown support using Pip Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Use this command for the recommended Pip user install, including Markdown support. ```bash python3 -m pip install --user "pelican[markdown]" ``` -------------------------------- ### Theme Development Workflow Example (Console) Source: https://github.com/getpelican/pelican/blob/main/docs/pelican-themes.rst Demonstrates a typical workflow for theme development using symbolic links, including editing CSS and HTML, and rebuilding the site. ```console $ sudo pelican-themes -s ~/Dev/Python/pelican-themes/two-column $ pelican ~/Blog/content -o /tmp/out -t two-column $ firefox /tmp/out/index.html $ vim ~/Dev/Pelican/pelican-themes/two-column/static/css/main.css $ pelican ~/Blog/content -o /tmp/out -t two-column $ cp /tmp/bg.png ~/Dev/Pelican/pelican-themes/two-column/static/img/bg.png $ pelican ~/Blog/content -o /tmp/out -t two-column $ vim ~/Dev/Pelican/pelican-themes/two-column/templates/index.html $ pelican ~/Blog/content -o /tmp/out -t two-column ``` -------------------------------- ### Install Feedparser for Medium Import Source: https://github.com/getpelican/pelican/blob/main/docs/importer.rst Before importing from a Medium RSS feed, install the feedparser library using pip. ```bash $ python -m pip install feedparser ``` -------------------------------- ### Install Pelican with Pipx Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Install Pelican using Pipx for isolated environments, including Markdown support. ```bash pipx install "pelican[markdown]" ``` -------------------------------- ### Install bleeding-edge Pelican from Git Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Install the latest development version of Pelican directly from its Git repository. ```bash python3 -m pip install -e "git+https://github.com/getpelican/pelican.git#egg=pelican" ``` -------------------------------- ### List Installed Themes (Console) Source: https://github.com/getpelican/pelican/blob/main/docs/pelican-themes.rst Use the -l or --list option to display installed themes. An '@' symbol indicates a symlinked theme. ```console $ pelican-themes -l notmyidea two-column@ simple ``` ```console $ pelican-themes --list notmyidea two-column@ simple ``` -------------------------------- ### Clone and Set Up Plugin Repository Source: https://github.com/getpelican/pelican/blob/main/docs/contribute.rst Clone a Pelican plugin repository and set up the project for local development. This includes adding the upstream remote and installing dependencies. ```bash git clone https://github.com/YOUR_USERNAME/simple-footnotes.git ~/projects/pelican-plugins/simple-footnotes cd ~/projects/pelican-plugins/simple-footnotes git remote add upstream https://github.com/pelican-plugins/simple-footnotes.git invoke setup ``` -------------------------------- ### Reproducing a Site Build Source: https://github.com/getpelican/pelican/blob/main/CONTRIBUTING.rst Use this command to attempt to build a site with a clean Pelican installation and a sample configuration. If this build succeeds, the issue is likely with your theme, plugins, or settings. ```bash cd ~/projects/your-site git clone https://github.com/getpelican/pelican ~/projects/pelican pelican content -s ~/projects/pelican/samples/pelican.conf.py -t ~/projects/pelican/pelican/themes/notmyidea ``` -------------------------------- ### Install Pelican without Markdown support using Pip Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Use this command for the recommended Pip user install if Markdown support is not needed. ```bash python3 -m pip install --user pelican ``` -------------------------------- ### Content Status Examples (reStructuredText and Markdown) Source: https://context7.com/getpelican/pelican/llms.txt Demonstrates how to set content status for articles and pages using reStructuredText and Markdown. Includes examples for 'draft' and 'hidden' statuses. ```rst Draft Article ############# :date: 2024-03-15 :status: draft This article is saved to the ``drafts/`` folder and excluded from indexes. ``` ```markdown Title: Not Found Status: hidden Save_as: 404.html The page you requested could not be found. Check the [Archives](/archives.html)? ``` -------------------------------- ### Pelican Configuration Settings (`pelicanconf.py`) Source: https://context7.com/getpelican/pelican/llms.txt Example Python code for the `pelicanconf.py` settings file. Demonstrates common settings like SITENAME, SITEURL, PATH, TIMEZONE, and URL/save-as patterns for articles and pages. ```python # pelicanconf.py SITENAME = "My Tech Blog" SITEURL = "" # empty for local dev; set full URL for production PATH = "content" TIMEZONE = "America/New_York" DEFAULT_LANG = "en" # URL and save-as patterns ARTICLE_URL = "{date:%Y}/{date:%m}/{slug}.html" ARTICLE_SAVE_AS = "{date:%Y}/{date:%m}/{slug}.html" PAGE_URL = "pages/{slug}.html" PAGE_SAVE_AS = "pages/{slug}.html" ``` -------------------------------- ### List Installed Themes Verbose (Console) Source: https://github.com/getpelican/pelican/blob/main/docs/pelican-themes.rst Combine the -l or --list option with -v or --verbose for detailed paths and symlink information. ```console $ pelican-themes -v -l /usr/local/lib/python2.6/dist-packages/pelican-2.6.0-py2.6.egg/pelican/themes/notmyidea /usr/local/lib/python2.6/dist-packages/pelican-2.6.0-py2.6.egg/pelican/themes/two-column (symbolic link to `/home/skami/Dev/Python/pelican-themes/two-column') /usr/local/lib/python2.6/dist-packages/pelican-2.6.0-py2.6.egg/pelican/themes/simple ``` -------------------------------- ### Combine Operations (Console) Source: https://github.com/getpelican/pelican/blob/main/docs/pelican-themes.rst The --install, --remove, and --symlink options can be used together in a single command to perform multiple operations simultaneously. ```console # pelican-themes --remove notmyidea-cms two-column \ --install ~/Dev/Python/pelican-themes/notmyidea-cms-fr \ --symlink ~/Dev/Python/pelican-themes/two-column \ ``` -------------------------------- ### Namespace Plugin Example Source: https://context7.com/getpelican/pelican/llms.txt A basic namespace plugin that hooks into Pelican's initialization and finalization signals, and injects a synthetic article. ```python import logging import datetime from pelican import signals from pelican.contents import Article from pelican.readers import BaseReader log = logging.getLogger(__name__) def on_initialized(pelican_obj): """Runs once after Pelican is initialized.""" log.info("Pelican initialized. Output: %s", pelican_obj.output_path) def inject_article(article_generator): """Inject a synthetic article before taxonomy is built.""" settings = article_generator.settings reader = BaseReader(settings) article = Article( content="

This article was injected by a plugin.

", metadata={ "title": "Auto-Generated Post", "date": datetime.datetime(2024, 1, 1), "category": reader.process_metadata("category", "meta"), "tags": reader.process_metadata("tags", "auto, generated"), "slug": "auto-generated-post", }, ) article_generator.articles.insert(0, article) def on_finalized(pelican_obj): """Runs after all generators have finished.""" log.info("Build complete.") def register(): signals.initialized.connect(on_initialized) signals.article_generator_pretaxonomy.connect(inject_article) signals.finalized.connect(on_finalized) ``` ```python # pelicanconf.py — enable the plugin PLUGINS = ["myplugin"] # short name for namespace plugin # or: PLUGINS = ["pelican.plugins.myplugin"] ``` -------------------------------- ### Pelican Configuration for Article Paths Source: https://github.com/getpelican/pelican/blob/main/docs/content.rst Example Pelican configuration settings to define article paths and output structure, used in conjunction with {attach} for static file management. ```python PATH = 'content' ARTICLE_PATHS = ['blog'] ARTICLE_SAVE_AS = '{date:%Y}/{slug}.html' ARTICLE_URL = '{date:%Y}/{slug}.html' ``` -------------------------------- ### Custom Reader Plugin Example Source: https://context7.com/getpelican/pelican/llms.txt Extends Pelican to parse custom file formats by subclassing BaseReader and registering it via the readers_init signal. ```python # pelican/plugins/asciireader/__init__.py from pelican import signals from pelican.readers import BaseReader class AsciiReader(BaseReader): enabled = True file_extensions = ["adoc", "asciidoc"] def read(self, filename): with open(filename, encoding="utf-8") as f: raw = f.read() # Extract a simple "= Title" header as title metadata lines = raw.splitlines() title = lines[0].lstrip("= ").strip() if lines else "Untitled" body = "\n".join(lines[1:]).strip() metadata = { "title": self.process_metadata("title", title), } # Return HTML body and processed metadata return f"

{body}

", metadata def add_reader(readers): readers.reader_classes["adoc"] = AsciiReader readers.reader_classes["asciidoc"] = AsciiReader def register(): signals.readers_init.connect(add_reader) ``` -------------------------------- ### Create a New Reader Plugin Source: https://github.com/getpelican/pelican/blob/main/docs/plugins.rst Example of a Python plugin to add support for a new input file format. It defines a new reader class and registers it using the `readers_init` signal. ```python from pelican import signals from pelican.readers import BaseReader # Create a new reader class, inheriting from the pelican.reader.BaseReader class NewReader(BaseReader): enabled = True # Yeah, you probably want that :-) # The list of file extensions you want this reader to match with. # If multiple readers were to use the same extension, the latest will # win (so the one you're defining here, most probably). file_extensions = ['yeah'] # You need to have a read method, which takes a filename and returns # some content and the associated metadata. def read(self, filename): metadata = {'title': 'Oh yeah', 'category': 'Foo', 'date': '2012-12-01'} parsed = {} for key, value in metadata.items(): parsed[key] = self.process_metadata(key, value) return "Some content", parsed def add_reader(readers): readers.reader_classes['yeah'] = NewReader # This is how pelican works. def register(): signals.readers_init.connect(add_reader) ``` -------------------------------- ### Automate Pelican Site Updates with Post-Commit Hook Source: https://github.com/getpelican/pelican/blob/main/docs/tips.rst This example provides a bash script for a Git post-commit hook. It automates the process of building the Pelican site, deploying it using ghp-import, and pushing the changes to the gh-pages branch. ```bash pelican content -o output -s pelicanconf.py && ghp-import output && git push origin gh-pages ``` -------------------------------- ### Specify Pelican Theme Source: https://github.com/getpelican/pelican/blob/main/docs/settings.rst Examples of how to set the THEME variable to use different themes. This can be a built-in theme name, a theme installed via pelican-themes, or a custom theme path. ```python THEME = "notmyidea" # Specify name of a theme installed via the pelican-themes tool THEME = "chunk" # Specify a customized theme, via path relative to the settings file THEME = "themes/mycustomtheme" # Specify a customized theme, via absolute path THEME = "/home/myuser/projects/mysite/themes/mycustomtheme" ``` -------------------------------- ### Advanced Code Block Options in reStructuredText Source: https://github.com/getpelican/pelican/blob/main/docs/content.rst The `code-block` directive in reStructuredText supports various options for customizing syntax highlighting. This example shows line numbers starting at 153 and a CSS class prefix. ```rst .. code-block:: identifier :classprefix: pgcss :linenos: table :linenostart: 153 ``` -------------------------------- ### Python Code Snippet with Line Numbers and Options Source: https://github.com/getpelican/pelican/blob/main/pelican/tests/output/custom_locale/posts/2010/octobre/15/unbelievable/index.html A more detailed Python code example demonstrating source code highlighting, including lexer selection, option handling for line numbers, and HTML formatter usage. This is useful for complex code presentations. ```python def run(self): self.assert_has_content() try: lexer = get_lexer_by_name(self.arguments[0]) except ValueError: # no lexer found - use the text one instead of an exception lexer = TextLexer() if ('linenos' in self.options and self.options['linenos'] not in ('table', 'inline')): self.options['linenos'] = 'table' for flag in ('nowrap', 'nobackground', 'anchorlinenos'): if flag in self.options: self.options[flag] = True # noclasses should already default to False, but just in case... formatter = HtmlFormatter(noclasses=False, **self.options) parsed = highlight('\n'.join(self.content), lexer, formatter) return [nodes.raw('', parsed, format='html')] ``` -------------------------------- ### Create a new Pelican project skeleton Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Use the pelican-quickstart command to generate a basic Pelican project structure. ```bash pelican-quickstart ``` -------------------------------- ### Create a new Pelican project at a specific path Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Use pelican-quickstart with the --path option to specify the directory for the new Pelican project. ```bash pelican-quickstart --path /your/desired/directory ``` -------------------------------- ### Install PDM Source: https://github.com/getpelican/pelican/blob/main/docs/contribute.rst Installs PDM, a Python package manager, for managing project dependencies and virtual environments. ```bash curl -sSL https://pdm.fming.dev/install-pdm.py | python3 - ``` -------------------------------- ### Create Project Directory and Navigate Source: https://github.com/getpelican/pelican/blob/main/docs/quickstart.rst Set up a new directory for your Pelican site and change into it. This is the first step in creating a new project. ```bash mkdir -p ~/projects/yoursite cd ~/projects/yoursite ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/getpelican/pelican/blob/main/docs/contribute.rst Build and serve the project documentation locally. Changes to documentation source files will automatically reload in the browser. ```bash invoke docserve ``` -------------------------------- ### Serve Site with Make Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Serve the generated site so it can be previewed in your browser at http://localhost:8000/. ```bash make serve ``` -------------------------------- ### Build Site with Invoke Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Execute the 'build' task defined in your 'tasks.py' file to generate the site. ```bash invoke build ``` -------------------------------- ### Install Markdown Library for Pelican Source: https://github.com/getpelican/pelican/blob/main/docs/faq.rst If you use Markdown content, install the Markdown library using pip. This is not a hard dependency for Pelican. ```bash python -m pip install markdown ``` -------------------------------- ### Publish Site with Make Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Generate the site for production using the settings in publishconf.py. ```bash make publish ``` -------------------------------- ### Generate Site with Make Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Run this command to generate your site using the settings in pelicanconf.py. ```bash make html ``` -------------------------------- ### Upload Site with Make Rsync Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Upload your site using rsync over SSH. This is one of the methods you might have chosen during the pelican-quickstart process. ```bash make rsync_upload ``` -------------------------------- ### Preview the Site Locally Source: https://github.com/getpelican/pelican/blob/main/docs/quickstart.rst Launch Pelican's built-in web server to preview your generated site. Access it via http://localhost:8000/ in your browser. ```bash pelican --listen ``` -------------------------------- ### Custom Generator Plugin Example Source: https://context7.com/getpelican/pelican/llms.txt Adds a new generator to Pelican, for example, to create a JSON API of articles alongside HTML output. ```python # pelican/plugins/json_api/__init__.py import json import os from pelican import signals from pelican.generators import Generator class JsonApiGenerator(Generator): """Writes a JSON index of all articles to output/api/articles.json.""" def generate_output(self, writer): api_dir = os.path.join(self.output_path, "api") os.makedirs(api_dir, exist_ok=True) articles = self.context.get("articles", []) data = [ { "title": a.title, "url": a.url, "date": a.date.isoformat(), "summary": getattr(a, "summary", ""), "tags": [t.name for t in getattr(a, "tags", [])], } for a in articles ] output_path = os.path.join(api_dir, "articles.json") with open(output_path, "w", encoding="utf-8") as f: json.dump(data, f, indent=2) def get_generators(pelican_obj): return JsonApiGenerator def register(): signals.get_generators.connect(get_generators) ``` -------------------------------- ### Basic Python Logging Source: https://github.com/getpelican/pelican/blob/main/docs/contribute.rst Demonstrates the standard Python way to initialize a logger and log a warning message with string formatting. ```python import logging logger = logging.getLogger(__name__) logger.warning("A warning with %s formatting", arg_to_be_formatted) ``` -------------------------------- ### Article Translation Example (French) Source: https://github.com/getpelican/pelican/blob/main/docs/content.rst Example of a French article with the same 'slug' as the English version and a 'lang' attribute set to 'fr'. This links it as a translation. ```markdown Foobar n'est pas mort ! ####################### :slug: foobar-is-not-dead :lang: fr Oui oui, foobar est toujours vivant ! ``` -------------------------------- ### Article Translation Example (English) Source: https://github.com/getpelican/pelican/blob/main/docs/content.rst Example of an English article with a 'slug' and 'lang' attribute for translation identification. The slug is used to link translations. ```markdown Foobar is not dead ################## :slug: foobar-is-not-dead :lang: en That's true, foobar is still alive! ``` -------------------------------- ### Article Metadata Example Source: https://github.com/getpelican/pelican/blob/main/docs/themes.rst Example of metadata in an article's source file. Custom metadata fields like `FacebookImage` are converted to lowercase and become accessible as attributes of the `article` object in templates. ```md Title: I love Python more than music Date: 2013-11-06 10:06 Tags: personal, python Category: Tech Slug: python-je-l-aime-a-mourir Author: Francis Cabrel FacebookImage: http://franciscabrel.com/images/pythonlove.png ``` -------------------------------- ### Publish Site with Invoke Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Use this command to publish your site via rsync over SSH, assuming you enabled this option during pelican-quickstart. ```bash invoke publish ``` -------------------------------- ### Upgrade Pelican using Pip Source: https://github.com/getpelican/pelican/blob/main/docs/install.rst Upgrade an existing Pip installation of Pelican to the latest stable release. ```bash python3 -m pip install --upgrade pelican ``` -------------------------------- ### Run Invoke Livereload Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Install livereload and then run this command to have Pelican automatically regenerate your site when changes are detected. ```bash invoke livereload ``` -------------------------------- ### Checking Pelican Version Source: https://github.com/getpelican/pelican/blob/main/CONTRIBUTING.rst Display the installed Pelican version. This information is required when reporting issues or seeking help. ```bash pelican --version ``` -------------------------------- ### Generating the Site with `pelican` CLI Source: https://context7.com/getpelican/pelican/llms.txt Various `pelican` CLI commands for generating the static site. Includes options for specifying content and output paths, verbosity, clean builds, overriding settings, and printing configuration. ```bash # Basic generation from the content/ directory pelican content # With explicit settings file and output path pelican content -s pelicanconf.py -o output/ # Enable all informational log messages pelican content -v # Delete output directory before generating (clean build) pelican content -d # Override specific settings from the command line (JSON values) pelican content -e SITEURL='"https://example.com"' CACHE_CONTENT=false # Print all resolved settings and exit pelican --print-settings # Print specific settings only pelican --print-settings SITEURL OUTPUT_PATH THEME ``` -------------------------------- ### Run Development Server with Make Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Simultaneously run Pelican in regeneration mode and serve the output at http://localhost:8000/. This combines 'make regenerate' and 'make serve'. ```bash make devserver ``` -------------------------------- ### Basic Source Code Directive Source: https://github.com/getpelican/pelican/blob/main/pelican/tests/output/basic/unbelievable.html A simple example of the source code directive. Use this for basic code inclusion. ```html formatter = self.options and VARIANTS[self.options.keys()[0]] ``` -------------------------------- ### Custom Writer Plugin Example Source: https://context7.com/getpelican/pelican/llms.txt Replaces or extends the default HTML writer, for instance, to minify whitespace in the output HTML. ```python # pelican/plugins/minify_writer/__init__.py import re from pelican import signals from pelican.writers import Writer class MinifyWriter(Writer): """Writes HTML output with whitespace minification.""" def write_file(self, name, template, context, **kwargs): # Call standard write, then minify the result super().write_file(name, template, context, **kwargs) output_path = self.output_path filepath = f"{output_path}/{name}" try: with open(filepath, "r+", encoding="utf-8") as f: content = f.read() # Simple whitespace collapse (use a real minifier in production) minified = re.sub(r">\s+<", "><", content) f.seek(0) f.write(minified) f.truncate() except FileNotFoundError: pass def get_writer(pelican_obj): return MinifyWriter def register(): signals.get_writer.connect(get_writer) ``` -------------------------------- ### Generate Site with Production Settings Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Generate your site using production-specific settings defined in 'publishconf.py'. ```bash pelican content -s publishconf.py ``` -------------------------------- ### Deploy Site with rsync Source: https://github.com/getpelican/pelican/blob/main/docs/publish.rst Use rsync to efficiently transfer your generated site files to a production server. The '--delete' option removes files on the destination that are no longer present in the source. ```bash rsync -avc --delete output/ host.example.com:/var/www/your-site/ ``` -------------------------------- ### Python Debugger Breakpoint Source: https://github.com/getpelican/pelican/blob/main/pelican/tests/output/basic/category/yeah.html Use this snippet to set a breakpoint in your Python code using the ipdb debugger. Ensure ipdb is installed. ```python >>> from ipdb import set_trace >>> set_trace() ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/getpelican/pelican/blob/main/docs/contribute.rst Manually creates and activates a Python virtual environment for Pelican development. ```bash mkdir ~/virtualenvs && cd ~/virtualenvs python3 -m venv pelican source ~/virtualenvs/pelican/*/activate ``` -------------------------------- ### reStructuredText Metadata Example Source: https://github.com/getpelican/pelican/blob/main/docs/content.rst Define article metadata using reStructuredText syntax. Supports date, tags, category, slug, and authors. ```rst My super title ############## :date: 2010-10-03 10:20 :modified: 2010-10-04 18:40 :tags: thats, awesome :category: yeah :slug: my-super-post :authors: Alexis Metaireau, Conan Doyle :summary: Short version for index and feeds ``` -------------------------------- ### Python Bitwise AND Operation Source: https://github.com/getpelican/pelican/blob/main/pelican/tests/content/article_with_code_block.rst This snippet shows a basic Python expression. Ensure the context supports Python execution if this were a live example. ```python x & y ``` -------------------------------- ### Configure develop-server.sh for SSL Source: https://github.com/getpelican/pelican/blob/main/docs/tips.rst This snippet shows how to integrate SSL certificate and key paths into a 'develop-server.sh' script for launching the Pelican development server with HTTPS support. ```bash CERT="$BASEDIR/cert.pem" KEY="$BASEDIR/key.pem" $PY -m pelican.server $port --ssl --cert="$CERT" --key="$KEY" & ``` -------------------------------- ### Configure Analytics Scripts Source: https://github.com/getpelican/pelican/blob/main/docs/settings.rst Example of how to include custom analytics scripts in your site. This setting is intended for use in `publishconf.py` and can contain HTML and JavaScript. ```python ANALYTICS = """ """ ```