datopian / flowershow

💐 Publish your obsidian digital garden or any markdown site easily and elegantly.
https://flowershow.app/
MIT License
839 stars 99 forks source link

Tool and Tutorial: migration wordpress to Markdown for Flowershow #258

Closed rufuspollock closed 1 year ago

rufuspollock commented 2 years ago

When on wordpress i want to switch to flowershow / nextjs because it is awesome so that i can maintain my site more easily etc

After running output is something like this:

about.md
/assets/
/blog/ # blog posts go here
/blog/2018/04/03/xxx-yyy.md

Acceptance

Tasks

Tutorial

Tool

Bonus

Notes

Blog setup in flowershow

Current fields:

Question

Change authors field type from https://www.contentlayer.dev/docs/reference/source-files/field-types#list

---
authors:
  - philippe
  - ...
---

to

---
authors: ['Philippe', '...']
---

Needed fields

Other changes

Current script output:

Changes in script

Assets

Current folder output

Modify script to below changes:

PhilippeduPreez commented 1 year ago

https://hackmd.io/Uq2yzonrQn6z2x8WfqjcIA

PhilippeduPreez commented 1 year ago

Used this so far Use https://github.com/lonekorean/wordpress-export-to-markdown

PhilippeduPreez commented 1 year ago

Current CLI setup:

image

PhilippeduPreez commented 1 year ago

@khalilcodes Just some problems that came up while testing the current tool

PhilippeduPreez commented 1 year ago

@khalilcodes also my headings seems to display correctly when using flowershow, so I think the problem lies in the new datopian version and not the exports.

rufuspollock commented 1 year ago

@PhilippeduPreez

hardcoded values to OG website like https://www.datopian.com/wp-content/uploads/2021/01/Group-4298_desktop.svg

This is why i think brute force migrating wp-content/uploads into the public folder is good idea (i've had this experience before). Can you get a wp-content/uploads export out of wordpress?

I'd also frankly do that with the images if you could and not bother rewriting them.

Some custom stuff like tables do not convert

this is fine. Just flag that in the tutorial / docs.

khalilcodes commented 1 year ago

@rufuspollock @PhilippeduPreez Since wordpress users are already aware of plugins, how about just using a free export wordpress plugin like https://wordpress.org/plugins/export-media-library/ and just putting that in the tutorial section eg. "exporting your wordpress assets" ?

PhilippeduPreez commented 1 year ago

@khalilcodes @rufuspollock I agree that we might need to go the export wordpress plugin route to match the correct folder structure. Exporting the media in xml and using https://github.com/lonekorean/wordpress-export-to-markdown will not produce any images as it only work on exporting "All content"

khalilcodes commented 1 year ago

@PhilippeduPreez pushed the changes to script we worked on. Note that the images folder now generates within the (output) directory. Also please confirm .svg path outputs.

Although we discussed, I'm not convinced if we should be prepending assets like so [](assets/images/...) since the assets folder could be named anything else in flowershow. What do you think ?

Other than that I think the html in frontmatter's title field would be left to look at and then we may have a ready to go script.

PhilippeduPreez commented 1 year ago

@khalilcodes another option to [](assets/images/...) could be to turn image links into wikilinks since they should be picked up anywhere in content folder as far as I understand. Then we don't need to specify an assets folder

khalilcodes commented 1 year ago

another option to could be to turn image links into wikilinks

@PhilippeduPreez that would be digging in more especially since the script uses an xml to markdown parser. Let's keep it default and go with [](images/...) imo.

PhilippeduPreez commented 1 year ago

@khalilcodes just and idea for future users we could ask the name of their assets folder in the wizard and append that before like [ ](name-of-assets-folder/images/...)

khalilcodes commented 1 year ago

@PhilippeduPreez pushed the tests.

PhilippeduPreez commented 1 year ago

@khalilcodes The date frontmatter ordering works, so we don't need to make any changes to the type

PhilippeduPreez commented 1 year ago
PhilippeduPreez commented 1 year ago

@khalilcodes @rufuspollock Links like these [on the value of data](https://www.datopian.com/2022/04/07/on-the-value-of-data/) will still cause problems atm. The tool is able to currently output year and month folders, so maybe we can add a day folder so these links will be functional?

PhilippeduPreez commented 1 year ago

@rufuspollock I confirmed with @olayway that the new flowershow blog setup should handle this correctly, then these links should still work

khalilcodes commented 1 year ago

@PhilippeduPreez I came across two changes and opened a PR for your review on these.

  1. Fix to titles being converted directly as slugs as seen below:

    Screen Shot 2022-11-29 at 6 56 48 PM
  2. Renaming the coverImage field to image in frontmatter. Since an image field is already present in flowershow blog/page definition, let's use that rather than separately adding a coverImage field in contentlayer.

PhilippeduPreez commented 1 year ago

@khalilcodes I opened a PR for your review on authors being added in frontmatter

image

olayway commented 1 year ago

@PhilippeduPreez, @khalilcodes please update the tasks in the description and add relevant comments :) @PhilippeduPreez if the PR you created will close this issue you can link the PR by adding Closes #<number of this issue> to its description.

khalilcodes commented 1 year ago

@PhilippeduPreez @olayway @rufuspollock One issue with images I have faced during migration is with the paths to any image files.

In Obsidan, we would write the path to the images like so - ![](assets/images/example.png). This then shows up the image but fails to load on the web since the path resolves as relative. for eg. <img src="https://next.lifeitself.org/<sub-dir>/assets/images/example.png" />

For it to load on the web, we would need to add a leading slash - ![](/assets/images/example.png), but then this fails to load in Obsidian.

To fix this issue we can modify the img tag in MDX.js to add a leading slash for local images (if they don't already have one) like below:

// in MDX.js

const components = {
  img: ({ src, ...rest }) => {
    // check if the image path is external or already has a leading slash
    const imageSrc = src.startsWith("http") || src.startsWith("/") ? src : `/${src}`
    return <img src={imageSrc} {...rest} />
  }
  ...
}

I believe we should backport this which will then allow users consistency as to being able to view the images in Obsidian as well as on the website.

Note: that wiki-links-plus already prepends a slash and that's why we probably never noticed this. This issue is more likely to happen when either converting from wordpress or for users who use the markdown image syntax. IMO consistency across platforms remain.

Let me know your thoughts :)

olayway commented 1 year ago

In Obsidan, we would write the path to the images like so -

Hmmm... but aren't we using this syntax for embedding local images in Obsidian? ![[<image file name>]]

olayway commented 1 year ago

Oh, right, but we probably don't want to convert it to Obsidian wiki links since the user might not be using Obsidian.

rufuspollock commented 1 year ago

@PhilippeduPreez @khalilcodes can you confirm how we handled assets other than images (e.g. pdfs etc) in the wp-content folder? Does that stuff get migrated (especially relevant for life itself migration #261 )

khalilcodes commented 1 year ago

@rufuspollock I had updated the code locally to download pdfs into the assets/ folder (not in assets/images/) and parse the paths in markdown. If that sounds right, I can push the code to the tool and include the pdfs in the PR here https://github.com/life-itself/community/pull/212

olayway commented 1 year ago

Closed with #336