bgadrian / medium-to-hugo

Medium stories exporter to markdown/hugo articles.
68 stars 10 forks source link

Improved images handling + tweaks for Tags parsing #5

Closed RaVbaker closed 5 years ago

RaVbaker commented 5 years ago

When importing posts from my medium page I discovered that sometimes links to assets in Medium are not having explicit file extension. But the default for such, since they are imported from Unsplash, is .jpg. So I reorganized the code a bit for that behavior.

Another missing feature related to images and exports from Medium was lack of details how the image was styled in original post. By looking up in Medium code I figured out there are few styles, described in parent <figure> tag classes:

plus sometimes it's not specified and then it's a regular image with same width as text.

The last two have also some extra details in parent HTML node which says how many images should there appear in a single row and it can vary how the image grid is shown. There is an excellent post that summarize what styles are possible for images on Medium: https://medium.com/@jeffreywang1183/medium-image-guideline-b0e2c4947d90 plus Medium has a support page about it: https://help.medium.com/hc/en-us/articles/215679797-Images

Based on that research and article about styling images in markdown: https://www.xaprb.com/blog/how-to-style-images-with-markdown/ I decided to add the image layout details to the <img src="..."/> attribute value in a form of #layoutName meta-information.

This way CSS rules like:

img[src$="#layoutFillWidth"] {
  // ...
}

and similar would allow to style the images accordingly without modifying the markdown and putting there plain HTML tags.

Hope the idea would be liked and will get an approval.

A complete list of possible suffixed of img-src values is:

In case Medium adds some new layouts there will be automatically supported. Thanks to the way that code takes anything what's after graf--layout prefix.

RaVbaker commented 5 years ago

@bgadrian I've also added two extra changes here. One for aliases for Drafts, since that section is not needed for them. Till now it was rendering just alias to homepage which was conflicting sometimes.

And I've also fixed Tags discovery on Medium posts, because the've changed the HTML/CSS on pages. Now it's CSS classes agnostic.

RaVbaker commented 5 years ago

If you would like to I can move the tags discovery/aliases for Drafts to separate PR.

bgadrian commented 5 years ago

Looks great! Thanks for your contribution