Creating New Posts in Nikola
Creating New Posts in Nikola
It's important to learn this so you're using the proper workflow. If you create a new post outside of the command line, your posts won't be properly formatted and won't be able to be published.
Step 1: Open the Command Line
Assuming you're using VSCode, open the command line by pressing Ctrl + Shift + P
and typing Terminal: Create New Integrated Terminal
. This will open a new terminal in the bottom of your VSCode window.
Step 2: Navigate to the Posts Directory
In the command line, type cd posts
and press enter. This will navigate you to the posts directory if you're not already there.
Step 3: Create a New Post
If you're creating a markdown file, type nikola new_post -f markdown -t "Your Post Title"
and press enter. If you're creating a Jupyter notebook, type nikola new_post -f ipynb -t "Your Post Title"
and press enter.
Step 4: Edit Your Post
Your post will be created in the posts directory. Open it up and confirm the values at the top. You may need to set the category
, description
, and tags
values.
Step 5: Publish Your Post
If you're using Github + Netlify ci/cd like I am, you can publish your post by pushing your changes to Github - but first be sure to build it locally and test it!
Note: You can use
nikola build --clean
to build and clean at the same time - do this if you find that the static file is not updating correctly in Nikola.
Open your command line tool and run the following commands:
-
Make changes to your Nikola site
For example, create or edit posts. -
Build the static site
Run the following command in your terminal:nikola build
-
Start a local web server
Run the following command in your terminal:nikola serve
-
Preview the site in your web browser
Go to http://localhost:8000 or the address shown in your terminal. -
Stop the local web server
Usually by pressingCtrl
+C
in the terminal. -
Add the changes to Git
Run the following command in your terminal:git add .
-
Commit the changes with a message
Run the following command in your terminal, replacing "Your meaningful commit message" with a description of the changes:git commit -m "Your meaningful commit message"
-
Push the changes to the remote Git repository
Run the following command in your terminal:git push origin main
That's it! You've created and published a new post in Nikola.