Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Wp2hugo: Best WordPress to Hugo migrator (written in Go) (github.com/ashishb)
106 points by todsacerdoti on Aug 28, 2024 | hide | past | favorite | 50 comments


From personal experience: if you’re looking to migrate from WP, I’d strongly recommend just extracting your posts via WordPress’s JSON API. I looked at several of these tools while planning a lift of a large blog to Hugo, and none of them ultimately worked as well as a small one-off Python script that pulled from the JSON API.

(Pulling from the API also means you won’t have to inject any code into your current WP instance.)


Last I checked, it won't capture many aspects like `featured images in a page`. Or even unpublished blogs. I wanted to migrate both.

Further, working offline on a single file makes the whole process hermetic. I needed that to build and improve `wp2hugo`.


You may need to authenticate with Application Password to access all information via REST API.


The file export (xml based) can be pretty reliable too.


What I would like to see is a local GUI app that generates a static site.

I like Hugo, Gatsby, Ghost, Jekyll, and alike, but ever try to explain how to manage it to a machinist?

If there is one out there, please let me know.


There have been a number of plugins that turn a Wordpress/other website platform site into a static site.

So you make dev.yourdomain.example.com and block it from basically everything, client logs in the there and does the needful, and then when done hits "publish" and the plugin writes out a static site to example.com


1. How many of them migrate tricky features like featured images? 2. How many of them preserve existing URLs and GUIDs? 3. How many of them preserve the default RSS feed URL (Hugo's default is different from WordPress)? 4. How many of them preserve embedded Google Maps?

These are several issues that forced me to write `wp2hugo` for migrating my personal website.



Commenting to follow up on this...at some point. I started such a tool, using Punct [1] as the markup environment (CommonMark with ability to generate custom elements using inline Racket code, but could just as well be plain CommonMark + metadata).

[1]: https://joeldueck.com/what-about/punct/


You can install Local WP to install WordPress locally, then use the Simply Static plugin to generate a static site.


That's what I do, and he happens to be a machinist and welder. The static site is generated from Local WP, pushed to a GitHub repo, which is connected to Cloudflare Pages, which hosts it for free with SSL. I even set up a website monitor in GitHub Actions, but still have a separate website monitoring service with alerts. All for free.


When I worked with Drupal years ago(i made good money specializing in Drupal for more than a decade) I remember it having a caching module that generated static html page of every content page and served it instead of rendering anew. Simple tech.


I was looking for that for a long time. The editing experience of static site generators is even bad for a technical person.

I switched to Kirby as a result of that, not static but simple php and file based.


I recommended using Publii (https://getpublii.com).


Using WordPress Export may lose some data, such as respondents' user agent. WordPress REST API has been more reliable in my opinion, and I've successfully used it to transfer the comments to Artalk.


Is Artalk better than Remark42? I am trying to decide which one to use for my website.

  - https://github.com/ArtalkJS/Artalk
  - https://github.com/umputun/remark42/


I didn't try Remark42, because Artalk has had an easier-to-understand backup/import format called Artran. I'm quite satisfied with Artalk now. Remark42 seems to have a similar format as well.


Last year, I moved my small WordPress blog (~100 posts) to Hugo, and tested a couple of these - I can't remember if I tried Wp2hugo, but ended up using wordpress-export-to-markdown ( https://github.com/lonekorean/wordpress-export-to-markdown ).

I probably could have tweaked it for my own purposes, but with only 100 posts, I just reviewed every one. It probably took me a few evenings to get everything looking right following the conversion.



I looked at your exporter for migrating my personal website. Like most other exporters, it gets the basics right but misses out on a lot of subtle features listed here https://github.com/ashishb/wp2hugo#goals-of-wp2hugo


I successfully exported small blogs using the wordpress-to-hugo-exporter plugin, but it times out on big blogs, even increasing max PHP runtime for scripts to several hours. I had no choice but to rely on an offline, desktop variant and wp2hugo is super fast.


Dubious claim of best aside...

This is licensed under CC BY-NC-SA 4.0. How does it apply here? If I migrate my commercial blog, will the license apply to generated contents?


Standard IANAL disclaimer applies.

It seems like the author wants to prevent commercial use of the software:

> I want this project to be as widely accessible as possible, while still funding the development costs. This project is completely free for non-commercial and personal usage. Commercial usage is restricted via a license. Feel free to contact me if you want to license this commercially

You're not permitted to use the tool to migrate your commercial blog. This is why BY-NC is not considered a free license in the most common definition of the term.

However, this license does not apply to the generated output. It only applies to the work the license is attached to. It's not a viral license in that sense. You can migrate your blog and later turn it into a commercial enterprise without risking copyright violations.

If you want to migrate your commercial blog, you should ask the author. They can license their code under any license they choose, so they could sell or give you a copy licensed such that you are legally permitted to use it commercially.


> It seems like the author wants to prevent commercial use of the software

Makes sense. Yeah, the license is probably appropriate then. Thanks for the explanation!


Assuming this doesn’t inject any spurious code of its own into the migrated content, and you don’t include the migrator itself in your sites distributed artifacts, you should be fine. The license only applies to the code, not to the things it touches.


> Dubious claim of best aside...

I looked at 10+ tools and tried them on my personal blog, all got the basics right but none did great work for the 300+ posts that I have. You can see the features here https://github.com/ashishb/wp2hugo#goals-of-wp2hugo

> If I migrate my commercial blog, will the license apply to generated contents?

Lots of individuals have personal non-commercial websites and my goal was to give them a free tool to migrate out from WordPress -> Hugo (or even a static site, in general).

I hope it is fair to say that the original author of the code deserves to capture some value for the commercial migrations.


This funny because I want to go in the opposite direction.


Why so?


Does this works with any other theme than PaperMod? It looks like the theme is hardcoded in this importer. It seems to also overwrite files in this theme instead of making use of the layouts folder?


Author of `wp2hugo` here.

1. Hugo does not allow custom fonts - it leaves it to themes 2. Controlling many aspects of UI is really hard while having an abstract theme

I do not like modifying some files but I could not figure out a better way to do it without modifying a few files. Feel free to send a PR or suggest a better approach.


"Best" in the subjective opinion of @todsacerdoti. I didn't think editorialising titles was allowed.


The author of the software called it like that. Maybe quotes would still make sense.


This is actually useful thing for me, I need to migrate a blog I have in a WordPress instance to a static page so I can host it on GitHub pages or something that is less expensive than the server I have WordPress going. Thanks


It’s kind of sad how I’ve gotten to the point where instead of saying to myself “oh boy, another X / Y / Z lang project!” I just sigh, grimace, and wonder why the tool matters to the end result. At least it doesn’t have a name that somehow awkwardly incorporates “go”.

Edit: wait a sec


well wait a minute that 'go' in 'hugo' could be considered pre-existing damage lol


It matters because as a FOSS project it determine how able you are to debug, fix, and/or modify the code yourself. I have definitely chosen FOSS software to use based on their language.


Exactly. Most people need to some familiarity with Go to do any serious Hugo template modifications. So, by using Go, I'm avoiding an extra learning curve for them.


Me: 'What the heck is Hugo? Never heard of it'

checks repository

11 years old, 77k stars.

The tech world is too big.


It's a static site generator. You have some templates, some content, some themes, all in a repo.

Hugo looks at that and generates some HTML that you then need to somehow serve yourself.

It has some positives and negatives with respect to WordPress. Mostly, unlike WordPress, you don't have auth (authentication AND authorization) within the system itself, but have some access to some repo+some CI system+some upload system+some HTTP server through.... some other means.


> The tech world is too big.

Had the same realization today.

Hugo was my first introduction to the idea of static site generators.

That got me thinking what other tools pre-dated it and then I found this excellent series on the evolution of SSGs [1].

The only name I recognize in there is Jekyll !!

1. https://cloudcannon.com/blog/ssg-history-1-before-jekyll/


Well, if it's written in Go it must be super special.


Hugo is written in Go, so of course it makes sense to clarify that this tool is also written in Go. And not PHP, which WordPress is written in.

That's a big advantage and is good to know for the users.


We’re talking about a immigration tool, not something used at runtime. The language such a tool is written in is completely irrelevant for using it.


not really. some aspects that make great tool

- easy distribution (like "go install")

- minimal dependencies, tests and thus stability and security (like go ecosystem)

- cross platform support

- source code proxies by Google, checksums, and prevention of attacks (thanks to security of go ecosystem)

overall, I would very much prefer some well done Go tool rather say Python, Javascript or binaries


All your requirements could equally well fulfilled by PHP:

- easy distribution (like "go install"): composer install works the same way.

- minimal dependencies, tests and thus stability and security (like go ecosystem): the packagist/PHP ecosystem is of very high quality in general, packages tend to have few dependencies, and have solid test coverage.

- cross platform support: PHP runs virtually everywhere.

- source code proxies by Google, checksums, and prevention of attacks (thanks to security of go ecosystem): Packagist might not be served directly by Google, but the entire infrastructure is built around GitHub, where published artifacts map to the source files on GitHub 1:1; so you can trust on Git refs as checksums.


You can run a Go binary without installing `Go`. Can you distribute PHP code as succinct binaries?


If you’re so inclined, you can: https://static-php.dev/

That was not what the parent post required, is also besides the point, and I wouldn’t recommend it. Go is a fine language, especially for standalone applications.

But downright dismissing PHP as obviously worse than Go doesn’t do another very fine language justice. PHP is capable of quite a lot really, is fast as heck, has an amazing ecosystem, and carries you all the way from quick prototype to stable production workload.

And yes: a tool to migrate a blog is something it effortlessly handles.


hm, right. I am not an expert in PHP (Hack from Meta does not count).

From what you explained, PHP is good choice here too then.


Right, but none of those have anything to do with Hugo being written in go.


As a user of FOSS tools, I love it when they are written in a compiled language.

For a Python/TS tool, the user needs the dev environment to run it. For a Go/Rust/C++ tool, the user does not need the dev environment to install it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: