-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96d5009
commit 4ac42ae
Showing
29 changed files
with
4,502 additions
and
8,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
# Editor configuration, see http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
medium-export | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2022, Brion Mario. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
const path = require('path'); | ||
|
||
module.exports = { | ||
env: { | ||
node: true, | ||
es6: true, | ||
}, | ||
plugins: ['@brionmario'], | ||
extends: [ | ||
'plugin:@brionmario/strict', | ||
'plugin:@brionmario/internal', | ||
'plugin:@brionmario/jest', | ||
'plugin:@brionmario/prettier', | ||
], | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
project: [path.resolve(__dirname, 'tsconfig.json')], | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
medium-export | ||
output |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,173 @@ | ||
[![Build Status](https://travis-ci.org/xdamman/mediumexporter.svg?branch=master)](https://travis-ci.org/xdamman/mediumexporter) | ||
[![Coverage Status](https://coveralls.io/repos/github/xdamman/mediumexporter/badge.svg?branch=master)](https://coveralls.io/github/xdamman/mediumexporter?branch=master) | ||
# medium-to-gatsby | ||
|
||
# Medium Exporter | ||
A CLI to convert your medium exported .html files to gatsby .md files. | ||
|
||
## Features | ||
- Converts medium .html files and outputs gatsby .md files. | ||
- Customize output via templates | ||
- Downloads post images from medium and saves locally | ||
- Handles embedded tweets | ||
- Inlines github gists | ||
- Allows default language for code blocks. | ||
- Skips over drafts and post replies. | ||
- Generates report when done. | ||
|
||
Export your stories published on medium.com to markdown. | ||
## Installation | ||
`$ npm install -g https://github.com/jamischarles/export-medium-to-gatsby` (maybe it'll go on npm eventually) | ||
|
||
## Usage | ||
## Steps | ||
1. [Download your medium posts as an archive from medium](https://help.medium.com/hc/en-us/articles/115004745787-Download-your-information). | ||
2. Install this CLI via #Installation step above | ||
3. Save a template file (see template section below) where you'll be running | ||
your export command. | ||
4. Customize the template.js file you downloaded to match the [frontmatter](https://jekyllrb.com/docs/front-matter/) fields your gatsby blog requires. Here you also define what folder in your blog medium images should be downloaded to. | ||
5. Run the CLI and use the `medium-export/posts` folder as the input, and for output either directly output to your `content/posts` folder, or copy it there after generating the files. | ||
6. Verify that the generated files are correct and looks good. | ||
7. Make any CSS and styling adjustments as needed. | ||
8. Do a happy dance. | ||
|
||
./index.js {url} | ||
-O, --output - write to specified output directory | ||
-I, --info – Show information about the medium post | ||
--hugo - enable gohugo.io shortcodes | ||
--frontmatter - enable frontmatter | ||
--jekyll - format content and images for us in Jekyll blogs | ||
## CLI Usage | ||
``` | ||
Usage | ||
$ medium2gatsby <src_file_or_folder> | ||
## CLI example | ||
Options | ||
--output, -o Destination folder for output files. Defaults to './'. | ||
--template, -t Template used to generate post files. | ||
--help, -h Shows usage instructions | ||
If not output directory is specified, images and content will be downloaded into `/content` | ||
Examples | ||
$ medium2gatsby . -o posts -t template.js | ||
$ medium2gatsby 2018-04-02_Introducing-the-react-testing-library----e3a274307e65.html -o output -t template.js | ||
$ medium2gatsby ~/Downloads/medium-export/posts -o . -t template.js | ||
``` | ||
|
||
./index.js https://medium.com/@PatrickHeneise/malaysia-16be98ab673e | ||
## Recommended styling | ||
### Images and subtitles | ||
Images and subtitles will been converted to | ||
`<figure><img><figcaption>Subtitle</figcaption>` same as medium used. | ||
|
||
## programmatic example | ||
Gatsby injects a `<p>` in there. To fix spacing I suggest you add the following to your template's | ||
CSS:`figure > p {margin-bottom:0px !important;}`. | ||
|
||
### get individual posts | ||
You can use `figure figcaption {}` to style image subtitles. | ||
|
||
async function example() { | ||
mediumexporter.getPost(link, { | ||
output: "content/posts", | ||
hugo: true, | ||
frontmatter: true | ||
}) | ||
} | ||
### Fenced Links | ||
If you used fenced links on medium to make links stand out, those links will now | ||
have show up as `<a href="some-link" class="fenced-link">some text</a>.` This | ||
CSS should approximate the medium fenced link style: | ||
```css | ||
.fenced-link { | ||
background-color:#0000000d; | ||
font-family:monospace; | ||
text-decoration:underline; | ||
padding:2px; | ||
} | ||
``` | ||
|
||
### get feeds (default page size is 10) | ||
|
||
const exporter = require('./index') | ||
exporter.getFeed('https://medium.com/feed/@xdamman', { output: 'content' }) | ||
|
||
## Customize via templates | ||
Based on which gatsby theme you're using you may need to generate different | ||
frontmatter fields. | ||
|
||
Here are some example `template.js` you can save and pass to the CLI via the `-t` flag. | ||
|
||
### Template ex1: Different folder for each post | ||
- specifies `2018-04-16` date format in frontmatter `date` field | ||
- generates a separate folder for each post ie: `content/posts/introducing-react/index.md | ||
- saves post images to `/images2` (relative to the post folder) | ||
- posts will show on site as `/posts/[slug-name]` | ||
- defauls all code fences to use `'js'` | ||
|
||
```js | ||
module.exports = { | ||
render: function(data) { | ||
// data.published is Date ISO format: 2018-04-16T14:48:00.000Z | ||
var date = new Date(data.published); | ||
var prettyDate = | ||
date.getFullYear() + | ||
'-' + | ||
(date.getMonth() + 1).toString().padStart(2, 0) + | ||
'-' + | ||
date | ||
.getDate() | ||
.toString() | ||
.padStart(2, 0); //2018-04-16 | ||
|
||
var template = `\ | ||
--- | ||
slug: "/posts/${data.titleForSlug}/" | ||
date: ${prettyDate} | ||
title: "${data.title}" | ||
draft: false | ||
description: "${data.description}" | ||
categories: [] | ||
keywords: [${data.tags.join(',')}] | ||
--- | ||
${data.body} | ||
`; | ||
|
||
return template; | ||
}, | ||
getOptions: function() { | ||
return { | ||
folderForEachSlug: true, // separate folder for each blog post, where index.md and post images will live | ||
imagePath: '/images2', // <img src="/images2/[filename]" >. Used in the markdown files. | ||
defaultCodeBlockLanguage: 'js', // code fenced by default will be ``` with no lang. If most of your code blocks are in a specific lang, set this here. | ||
}; | ||
}, | ||
}; | ||
|
||
``` | ||
|
||
### Template ex2: Same folder for all posts | ||
- specifies `2018-04-16T14:48:00.000Z` date format (ISO, which is default) in frontmatter `date` field | ||
- saves all generated posts to same folder defined in `-o` options for CLI. Files are named via slug name from medium. | ||
- saves post images to `/Users/jacharles/dev/blog/content/posts/introducing-the-react-testing-library/images` | ||
- defauls all code fences to use `''` (no language). | ||
|
||
```js | ||
module.exports = { | ||
render: function(data) { | ||
var template = `\ | ||
--- | ||
slug: ${data.titleForSlug} | ||
date: ${data.published} | ||
title: "${data.title}" | ||
template: "post" | ||
draft: false | ||
description: "${data.description}" | ||
category: "" | ||
tags: [${data.tags.join(',')}] | ||
--- | ||
${data.body} | ||
`; | ||
|
||
return template; | ||
}, | ||
getOptions: function() { | ||
return { | ||
folderForEachSlug: false, // same folder for all posts | ||
imagePath: '/media', // <img src="/media/[filename]" >. Used in the markdown files. | ||
// This field is ignored when folderForEachSlug:true. Should be absolute. Location where medium images will be saved. | ||
imageFolder: | ||
'/Users/jacharles/dev/blog/static/media', | ||
defaultCodeBlockLanguage: '', // code fenced by default will be ``` with no lang. If most of your code blocks are in a specific lang, set this here. | ||
}; | ||
}, | ||
}; | ||
|
||
``` | ||
|
||
## TODO and Help needed | ||
I'm about ready to move on from this, but would love help with the following if | ||
anybody feels inclined: | ||
- [ ] Better progress / error messages. Should notify which articles fail for whichever reason | ||
- [ ] Error handling is very lacking in many places. Could / should be improved to be more robust especially around downloading posts / images from medium. | ||
- [ ] Adding tests (prefer something dead simple like mocha). Currently there | ||
are zero tests. | ||
- [ ] More generator targets. This repo could fairly easily be forked and expanded to include other targets like jekyll, or | ||
other static site generators. (low priority) (medium2markdown) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env node | ||
|
||
//executable CLI entry point into this util | ||
require('../lib/index.js'); |
Oops, something went wrong.