How to publish from Obsidian notes
I want to publish posts in my website directly from my Obsidian notes:
- to reduce the work necessary to publish and focus only on writing.
- possibly for free
After some research I have found that it is possible for free using various apps.
Note 1: The website that will be created is a static website.
Note 2: I actually pay a little fee per year because I decided to have a custom domain, so I pay for the registration of the domain. If you don’t want a custom domain or have a free domain, it is completely free.
These apps are:
Apps | Work done |
---|---|
Gitlab and in particular Gitlab Pages | Distribute your website |
Hugo | Build your static website |
Obsidian-export | Automatically copy the Obsidian notes you want to publish in a repository |
I won’t go into details of every step of the procedure because the link below are almost self-explaining. If you have problems, feel free to contact me. If I can help, I will certainly do.
Prerequisites
- An Obsidian vault where you write your notes
- A Gitlab account
Main steps to do only one time
- Install the various apps
- Set up a git repository
- Set up a theme for your website
- Set up Gitlab Pages config file
- Fix the render-link and render-image files
- If you want, set up your custom domain
Install the various apps
- Install Git https://git-scm.com/downloads
- Install obsidian-export https://github.com/zoni/obsidian-export
- Install Rust https://www.rust-lang.org/tools/install
- Install Visual Studio installer. This is required during the Rust installation.
- Install Rust https://www.rust-lang.org/tools/install
- Install Hugo (the extended version) https://gohugo.io/installation/windows/
- Install Go https://go.dev/doc/install
Set up a git repository
Fork, clone or create a git repository. This will be the repository that contains the files necessary to setup the static website with your Obsidian notes. (see https://gitlab.com/pages/hugo)
Set up a theme for your website
- Install Loveit theme https://hugoloveit.com/theme-documentation-basics/
- Modify
config.toml
file to configure your website template
Set up Gitlab Pages config file
Modify .gitlab-ci.yml
file to configure the Gitlab Pages. My file looks like this:
|
|
Fix the render-link and render-image files
- To publish correctly Obsidian link like
[[MyLink]]
, modify therender-link
file contained in the directory...\hugo\themes\LoveIt\layouts\_default\_markup
in the following way:
|
|
- To publish correctly images, modify the
render-image
file contained in the directory...\hugo\themes\LoveIt\layouts\_default\_markup
in the following way:
|
|
Note: If the directory where the images of your Obsidian vault will be exported is different from posts/attachments/
, you need to change the line {{- printf "/%s%s" "posts/attachments/" .Destination | safeURL -}}
accordingly.
Set up your custom domain
If you want to set up your own domain, then follow the following instructions https://docs.gitlab.com/ee/user/project/pages/custom_domains_ssl_tls_certification/
Note: The instructions in the above link did not work for me. I needed to set up the DNS records as follows:
Record A
Host name | Address |
---|---|
[] | 35.185.44.232 |
www | 35.185.44.232 |
I do not set a Record CNAME.
Record TXT
Host name | Value |
---|---|
[] | _gitlab-pages-verification-code.mylearningnotes.org TXT gitlab-pages-verification-code=YOUR_VERIFICATION_CODE_FOR_ROOT_DOMAIN |
_gitlab-pages-verification-code.www |
gitlab-pages-verification-code=YOUR_VERIFICATION_CODE_FOR_SUBDOMAIN |
Main steps to do every time you write contents
- Create some contents
- Check contents before publishing
- Publish your contents
Create some contents
- Create some content files in the content directory like the About page
- Write the content you want to publish in obsidian. I created the following structure:
- I have a Published directory in my obsidian vault.
- Under the Published directory, I have:
- an attachments directory where I save all the images linked in the posts.
- All the notes that I want to publish.
Check contents before publishing
- When ready to publish, run the
obsidian-export
command.- The first directory of the command is the source where the obsidian notes are contained. In my case is
C:\...\My_obsidian_vault\Published
- The second directory of the command is the destination where the obsidian notes will be copied. In my case is
C:\...\content\posts
- The first directory of the command is the source where the obsidian notes are contained. In my case is
- Run
hugo server
command and then open the//localhost:1313/
in your browser to see a preview of the website.
Publish your contents
- When ready to publish
- Run
hugo
command. - Commit and push. Gitlab automatically run the ci pipeline and build your website.
Note: if you want to push without running the ci pipeline, then push with the following option
git push -o ci.skip
- Run
- Go to
namespace.gitlab.io
or to your own domain to see your website.
Comments