### Serve Command Implementation Source: https://github.com/getnikola/nikola/blob/master/docs/sphinx/extending.rst Example of a command plugin's execute method, which starts a test HTTP server. It checks for the output directory and serves files from it. ```python def _execute(self, options, args): """Start test server.""" out_dir = self.site.config['OUTPUT_FOLDER'] if not os.path.isdir(out_dir): print("Error: Missing '{0}' folder?".format(out_dir)) return 1 # Exit code on failure. (return 0 not necessary) else: os.chdir(out_dir) httpd = HTTPServer((options['address'], options['port']), OurHTTPRequestHandler) sa = httpd.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "...") httpd.serve_forever() ``` -------------------------------- ### Install a Theme with Nikola CLI Source: https://github.com/getnikola/nikola/blob/master/docs/manual.rst Install a theme using the 'nikola theme -i ' command. This example installs the 'blogtxt' theme. ```console $ nikola theme -i blogtxt [2013-10-12T16:46:13Z] NOTICE: theme: Downloading: https://themes.getnikola.com/v6/blogtxt.zip [2013-10-12T16:46:15Z] NOTICE: theme: Extracting: blogtxt into themes ``` -------------------------------- ### Install Tooltip.js with npm Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/popper.js/README.md Use npm to install Tooltip.js for your project. ```bash npm install tooltip.js --save ``` -------------------------------- ### Install a Plugin Source: https://github.com/getnikola/nikola/blob/master/docs/manual.rst Install a plugin from the Nikola Plugins Index using the 'nikola plugin --install ' command. This command downloads, extracts, and installs the plugin, including any Python dependencies and sample configuration files. ```console $ nikola plugin --install helloworld ``` -------------------------------- ### Install Bootstrap with npm Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/bootstrap/README.md Install Bootstrap using npm for front-end projects. ```bash npm install bootstrap ``` -------------------------------- ### Install Bootstrap with yarn Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/bootstrap/README.md Install Bootstrap using yarn for front-end projects. ```bash yarn add bootstrap@4.6.2 ``` -------------------------------- ### Install Bootstrap with Composer Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/bootstrap/README.md Install Bootstrap using Composer for PHP projects. ```bash composer require twbs/bootstrap:4.6.2 ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/getnikola/nikola/blob/master/CONTRIBUTING.rst Install all necessary dependencies to run the Nikola test suite. ```bash pip install '.[extras,tests]' ``` -------------------------------- ### Nikola Serve Command Example Source: https://github.com/getnikola/nikola/blob/master/docs/extending.rst Example of running the 'nikola serve' command with a custom port. This demonstrates how to override default settings for the test server. ```console $ nikola serve -p 9000 Serving HTTP on 127.0.0.1 port 9000 ... ``` -------------------------------- ### Start Test Server Command Source: https://github.com/getnikola/nikola/blob/master/docs/extending.rst This Python code defines a command to start a test HTTP server. It checks for the output directory and serves files from it. Use this for local testing of your site. ```python 'default': '127.0.0.1', 'help': 'Address to bind', }, ) def _execute(self, options, args): """Start test server.""" out_dir = self.site.config['OUTPUT_FOLDER'] if not os.path.isdir(out_dir): print("Error: Missing '{0}' folder?".format(out_dir)) return 1 # Exit code on failure. (return 0 not necessary) else: os.chdir(out_dir) httpd = HTTPServer((options['address'], options['port']), OurHTTPRequestHandler) sa = httpd.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "...") httpd.serve_forever() ``` -------------------------------- ### Install Nikola with extras Source: https://github.com/getnikola/nikola/blob/master/CHANGES.txt Use this command to install Nikola with optional extras, which was previously handled by requirements-full.txt. ```bash pip install nikola[extras] ``` -------------------------------- ### Install Popper.js with Bower Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/popper.js/README.md Use Bower to install Popper.js and save it as a project dependency. ```bash bower install popper.js --save ``` -------------------------------- ### Install Popper.js with NuGet Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/popper.js/README.md Use the NuGet Package Manager console to install Popper.js. ```powershell PM> Install-Package popper.js ``` -------------------------------- ### Install Bootstrap CSS with NuGet Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/bootstrap/README.md Install Bootstrap CSS using NuGet package manager. ```powershell Install-Package bootstrap ``` -------------------------------- ### Install Tooltip.js with Bower Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/popper.js/README.md Use Bower to install Tooltip.js via its unpkg.com CDN. Note that this method does not allow specifying a version. ```bash bower install tooltip.js=https://unpkg.com/tooltip.js --save ``` -------------------------------- ### Shortcode Syntax Example Source: https://github.com/getnikola/nikola/blob/master/docs/extending.rst Example of a raw shortcode usage within Nikola templates. ```text {{% raw %}}{{% foo bar baz=bat beep %}}{{% /foo %}}{{% /raw %}} ``` -------------------------------- ### Install a Nikola Theme Source: https://github.com/getnikola/nikola/blob/master/nikola/data/samplesite/pages/manual.rst This console command installs a specified theme (e.g., 'blogtxt') from the Nikola theme repository. It downloads and extracts the theme into the themes directory. ```console $ nikola theme -i blogtxt [2013-10-12T16:46:13Z] NOTICE: theme: Downloading: https://themes.getnikola.com/v6/blogtxt.zip [2013-10-12T16:46:15Z] NOTICE: theme: Extracting: blogtxt into themes ``` -------------------------------- ### Template-Based Shortcode Jinja2 Example Source: https://github.com/getnikola/nikola/blob/master/docs/extending.rst An example of a Jinja2 template file used to render a shortcode, showing how arguments are accessed. ```jinja
{{ bar }}
``` -------------------------------- ### Install Jekyll and Clone Lanyon Theme Source: https://github.com/getnikola/nikola/blob/master/docs/creating-a-theme.rst Installs Jekyll, clones the Lanyon theme repository, builds it, and serves it locally for preview. This is a prerequisite for porting the theme. ```bash sudo apt-get install jekyll git clone git@github.com:poole/lanyon.git cd lanyon && jekyll build jekyll serve & google-chrome http://localhost:4000 ``` -------------------------------- ### Install Tooltip.js with yarn Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/popper.js/README.md Use yarn to add Tooltip.js to your project dependencies. ```bash yarn add tooltip.js ``` -------------------------------- ### JSON Data File Example Source: https://github.com/getnikola/nikola/blob/master/docs/manual.rst A sample JSON file that can be placed in the 'data/' directory to provide data to templates. ```json { "bar": "baz" } ``` -------------------------------- ### Install baguetteBox.js via Yarn Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/baguettebox.js/README.md Use Yarn to add baguetteBox.js to your project. ```sh yarn add baguettebox.js ``` -------------------------------- ### Initialize Nikola Demo Site Source: https://github.com/getnikola/nikola/blob/master/CONTRIBUTING.rst Create a quick demo site to test Nikola's build process without errors. ```bash nikola init -qd demosite ``` -------------------------------- ### reStructuredText Comment Example Source: https://github.com/getnikola/nikola/blob/master/nikola/data/samplesite/pages/quickref.rst Text starting with explicit markup but not matching other constructs is treated as a comment. This example shows how such text is ignored in rendering. ```plaintext .. This text will not be shown (but, for instance, in HTML might be rendered as an HTML comment) ``` -------------------------------- ### Configuration Inheritance Example Source: https://github.com/getnikola/nikola/blob/master/docs/manual.rst Demonstrates how to inherit settings from a base configuration file. Useful for managing configurations across different environments like development and production. ```python BLOG_AUTHOR = "Your Name" BLOG_TITLE = "Demo Site" SITE_URL = "https://yourname.github.io/demo-site BLOG_EMAIL = "joe@demo.site" BLOG_DESCRIPTION = "This is a demo site for Nikola." ``` ```python import conf globals().update(vars(conf)) SITE_URL = "http://localhost:8000/" ``` ```python from conf import * SITE_URL = "http://localhost:8000/" ``` -------------------------------- ### Initialize Nikola Site with Options Source: https://github.com/getnikola/nikola/blob/master/docs/man/nikola.rst Initializes a new Nikola site, with options for demo content, quiet mode, and specifying the output folder. ```bash nikola init [-d|--demo] [-q|--quiet] folder ``` -------------------------------- ### Build LiveReload.js Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/livereload-js/README.md To build the LiveReload.js project, you need Node.js and npm installed. After installing prerequisites with `npm install`, run `grunt build` to compile the project. ```bash npm install grunt build ``` -------------------------------- ### Configuration Inheritance Example Source: https://github.com/getnikola/nikola/blob/master/nikola/data/samplesite/pages/manual.rst Demonstrates how to inherit settings from a base configuration file into a specific environment configuration, such as for local development. ```python import conf globals().update(vars(conf)) SITE_URL = "http://localhost:8000/" ``` ```python from conf import * SITE_URL = "http://localhost:8000/" ``` -------------------------------- ### Initialize Nikola Site with Demo Content Source: https://github.com/getnikola/nikola/blob/master/docs/creating-a-theme.rst Initializes a new Nikola site with demo content using the 'nikola init' command with the '--demo' flag. This sets up a basic site structure and configuration. ```bash $ nikola init --demo lanyon-port Creating Nikola Site ==================== This is Nikola v7.8.0. We will now ask you a few easy questions about your new site. If you do not want to answer and want to go with the defaults instead, simply restart with the `-q` parameter. --- Questions about the site --- Site title [My Nikola Site]: Site author [Nikola Tesla]: Site author's e-mail [n.tesla@example.com]: Site description [This is a demo site for Nikola.]: Site URL [https://example.com/]: --- Questions about languages and locales --- We will now ask you to provide the list of languages you want to use. Please list all the desired languages, comma-separated, using ISO 639-1 codes. The first language will be used as the default. Type '?' (a question mark, sans quotes) to list available languages. Language(s) to use [en]: Please choose the correct time zone for your blog. Nikola uses the tz database. You can find your time zone here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Time zone [UTC]: Current time in UTC: 16:02:07 Use this time zone? [Y/n] --- Questions about comments --- You can configure comments now. Type '?' (a question mark, sans quotes) to list available comment systems. If you do not want any comments, just leave the field blank. Comment system: That's it, Nikola is now configured. Make sure to edit conf.py to your liking. If you are looking for themes and addons, check out https://themes.getnikola.com/ and https://plugins.getnikola.com/. Have fun! [2015-05-28T16:02:08Z] INFO: init: A new site with example data has been created at lanyon-port. [2015-05-28T16:02:08Z] INFO: init: See README.txt in that folder for more information. ``` -------------------------------- ### Initialize Nikola Demo Site Source: https://github.com/getnikola/nikola/blob/master/docs/social_buttons.rst Use this command to create a new Nikola site with example data for testing purposes. Navigate into the created directory afterward. ```bash nikola init --demo ssp_test See README.txt in that folder for more information. cd ssp_test/ ``` -------------------------------- ### Initialize Nikola Demo Site Source: https://github.com/getnikola/nikola/blob/master/docs/sphinx/social_buttons.rst Use this command to create a new Nikola site with example data for testing purposes. Navigate into the created directory afterwards. ```bash nikola init --demo ssp_test See README.txt in that folder for more information. $ cd ssp_test/ ``` -------------------------------- ### Serve Nikola Site with Options Source: https://github.com/getnikola/nikola/blob/master/docs/man/nikola.rst Starts the development web server for your Nikola site, allowing configuration of port, address, detachment, browser opening, and IPv6. ```bash nikola serve [-p PORT] [-a ADDRESS] [-d|--detach] [-b|--browser] [-6|--ipv6] ``` -------------------------------- ### Basic Site Configuration Source: https://github.com/getnikola/nikola/blob/master/docs/manual.rst Example of a fundamental configuration setting in Nikola's 'conf.py' for the blog author's name. ```python BLOG_AUTHOR = "Your Name" # (translatable) ``` -------------------------------- ### Install Merge in Node.js Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/merge/README.md Install the merge library using npm for Node.js projects. ```sh npm install merge --save ``` -------------------------------- ### Install baguetteBox.js via npm Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/baguettebox.js/README.md Use npm to install baguetteBox.js as a project dependency. ```sh npm install baguettebox.js --save ``` -------------------------------- ### Initialize New Nikola Site Source: https://github.com/getnikola/nikola/blob/master/docs/man/nikola.rst Use this command to create an empty Nikola site. For a site with demo files, use the --demo flag. ```bash nikola init mysite ``` ```bash nikola init --demo mysite ``` -------------------------------- ### Shortcode Syntax Examples Source: https://github.com/getnikola/nikola/blob/master/docs/extending.rst Illustrates the different syntaxes for using shortcodes, including those with no arguments, single arguments, named arguments, and content between opening/closing tags. ```text {{% raw %}}{{% foo %}}{{% /raw %}} # No arguments {{% raw %}}{{% foo bar %}}{{% /raw %}} # One argument, containing "bar" {{% raw %}}{{% foo bar baz=bat %}}{{% /raw %}} # Two arguments, one containing "bar", one called "baz" containing "bat" {{% raw %}}{{% foo %}}Some text{{% /foo %}}{{% /raw %}} # one argument called "data" containing "Some text" ``` -------------------------------- ### Install jQuery in Node.js Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/jquery/README.md Install the jQuery package using npm for use in a Node.js environment. ```sh npm install jquery ``` -------------------------------- ### Serve Nikola Site Locally Source: https://github.com/getnikola/nikola/blob/master/docs/man/nikola.rst Starts the development web server for your Nikola site and automatically opens it in a browser. ```bash nikola serve -b ``` -------------------------------- ### Install Bootstrap Sass with NuGet Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/bootstrap/README.md Install Bootstrap Sass using NuGet package manager. ```powershell Install-Package bootstrap.sass ``` -------------------------------- ### Initialize baguetteBox.js Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/baguettebox.js/README.md Run baguetteBox.js to initialize the lightbox on elements with the '.gallery' class. ```js baguetteBox.run('.gallery'); ``` -------------------------------- ### Initialize a New Nikola Site Source: https://github.com/getnikola/nikola/blob/master/docs/sphinx/creating-a-site.rst Use this command to create a new, empty Nikola site structure in the specified directory. ```console $ nikola init mysite Creating Nikola Site ==================== ⋮ [1970-01-01T00:00:00Z] INFO: init: Created empty site at mysite. ``` -------------------------------- ### Install baguetteBox.js via Bower Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/baguettebox.js/README.md Install baguetteBox.js using Bower for front-end package management. ```sh bower install baguettebox.js --save ``` -------------------------------- ### Nikola Help Serve Command Output Source: https://github.com/getnikola/nikola/blob/master/docs/extending.rst Example output from 'nikola help serve' showing available options and their defaults. This helps users understand how to configure the serve command. ```console $ nikola help serve nikola serve [options] start the test webserver Options: -p ARG, --port=ARG Port number [default: 8000] -a ARG, --address=ARG Address to bind [default: 127.0.0.1] ``` -------------------------------- ### Install Popper.js with npm Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/popper.js/README.md Use npm to install Popper.js for your project. Add this to your project's dependencies. ```bash npm install popper.js --save ``` -------------------------------- ### Install livereload-js via Bower Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/livereload-js/README.md Install livereload-js using Bower for development. This provides a single script file, dist/livereload.js. ```bash bower install livereload-js --save-dev ``` -------------------------------- ### Build and Serve Nikola Site Source: https://github.com/getnikola/nikola/blob/master/docs/sphinx/creating-a-site.rst Commands to build the static site and serve it locally for preview. 'nikola build' renders all site content, and 'nikola serve' starts a local web server. ```console $ nikola build Scanning posts.done! . render_site:output/categories/index.html . render_sources:output/index.txt . render_rss:output/rss.xml ⋮ ``` ```console $ nikola serve [1970-01-01T00:00:00Z] INFO: serve: Serving HTTP on 0.0.0.0 port 8000... ``` -------------------------------- ### Install livereload-js via npm Source: https://github.com/getnikola/nikola/blob/master/npm_assets/node_modules/livereload-js/README.md Install livereload-js using npm. Note that this package relies on window and document globals and is not intended for production builds. ```bash npm install livereload-js --save ``` -------------------------------- ### Configure Image and Gallery Folders Source: https://github.com/getnikola/nikola/blob/master/nikola/data/samplesite/pages/manual.rst Set up source and destination folders for galleries and images. Defines thumbnail sizes and image processing options. ```python GALLERY_FOLDERS = {"galleries": "galleries"} THUMBNAIL_SIZE = 180 MAX_IMAGE_SIZE = 1280 USE_FILENAME_AS_TITLE = True EXTRA_IMAGE_EXTENSIONS = [] GALLERIES_USE_THUMBNAIL = False GALLERIES_DEFAULT_THUMBNAIL = None GALLERY_SORT_BY_DATE = True IMAGE_FOLDERS = {'images': 'images'} IMAGE_THUMBNAIL_SIZE = 400 IMAGE_THUMBNAIL_FORMAT = '{name}.thumbnail{ext}' ```