kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
874 stars 132 forks source link

Org subtree as Markdown Headline 1 #712

Open geometryolife opened 1 year ago

geometryolife commented 1 year ago

Actual Behavior

---
title: "My first docs"
draft: true
---

## H1 {#h1}

### S1 {#s1}

### S2 {#s2}

## H2 {#h2}

### Sub {#sub}

## H3 {#h3}

Expected Behavior

---
draft: true
---

# My first docs

## H1 {#h1}

### S1 {#s1}

### S2 {#s2}

## H2 {#h2}

### Sub {#sub}

## H3 {#h3}

How to Reproduce the Issue

Example Org File

#+hugo_base_dir: .
#+hugo_section: docs
#+hugo_front_matter_format: yaml

* Aptos Move by Example

** TODO My first docs
:PROPERTIES:
:EXPORT_FILE_NAME: my-first-docs
:END:
*** H1
**** S1
**** S2

*** H2

**** Sub

*** H3

Generated Markdown File or Error

Ox-Hugo Debug Information

Debug Info
kaushalmodi commented 1 year ago

Hello, this is the expected behavior.

Markdown doesn't have a "title" syntax. So the Org mode title gets converted to Hugo markdown's title front-matter.

The Hugo template usually renders the title front-matter as h1 HTML tag. So the headings of the post are exported as ## in Markdown so that they get rendered to h2 in HTML.

kaushalmodi commented 1 year ago

Here's a workaround.. but I really really do NOT recommend going this route.

#+hugo_base_dir: .
#+hugo_section: docs
#+hugo_front_matter_format: yaml
#+hugo_level_offset: 0
#+options: author:nil

* Aptos Move by Example

** TODO Dummy title -- Make sure you don't render the title front-matter in Hugo templates
:PROPERTIES:
:EXPORT_FILE_NAME: my-first-docs
:END:
*** My first docs
**** H1
***** S1
***** S2
**** H2
***** Sub
**** H3

Markdown export:

---
title: "Dummy title – Make sure you don't render the title front-matter in Hugo templates"
draft: true
---

# My first docs {#my-first-docs}

## H1 {#h1}

### S1 {#s1}

### S2 {#s2}

## H2 {#h2}

### Sub {#sub}

## H3 {#h3}
geometryolife commented 1 year ago

Thank you @kaushalmodi Thanks for your answer, I saw this method from #375, I also think this method is not very good. I'd like to request this feature, and it would be nice to add a property to ox-hugo to do this. In fact, Markdown Docs of many document frameworks will use # as the Headline 1 of a file, such as Docusaurus, hugo-book etc.

kaushalmodi commented 1 year ago

In fact, Markdown Docs of many document frameworks will use # as the Headline 1 of a file, such as Docusaurus, hugo-book etc.

Thank you. I was not aware of that.

I'd like to request this feature, and it would be nice to add a property to ox-hugo to do this.

I am severely restricted on my time for this project as I still need to fix the GHA CI before I make any changes. I would believe that any Hugo project should respect the title in the title front-matter and render that as h1 tag. If this feature gets implemented in the future, it shouldn't need you to change any of your Org mode content.

geometryolife commented 1 year ago

If this feature gets implemented in the future, it shouldn't need you to change any of your Org mode content.

Thanks, some frameworks treat docs and blog types differently, docs type documents use # as the title, and bolg type documents use title in front-matter as the title.

kaushalmodi commented 1 year ago

docs type documents use # as the title, and bolg type documents use title in front-matter as the title.

I hope it is easy to fix that inconsistency in the framework's Hugo template.

Pseudocode:

if (title != "") {
  Render title as h1
}