1 | # gatsby-source-medium-backup
|
2 |
|
3 | [](./LICENSE)
|
4 | [](https://www.npmjs.com/package/gatsby-source-medium-backup)
|
5 | [](https://npmcharts.com/compare/gatsby-source-medium-backup?minimal=true)
|
6 | [](https://npmcharts.com/compare/gatsby-source-medium-backup?minimal=true)
|
7 | [](https://github.com/eugenehp/gatsby-source-medium-backup/watchers)
|
8 | [](https://github.com/eugenehp/gatsby-source-medium-backup/stargazers)
|
9 | [](https://github.com/eugenehp/gatsby-source-medium-backup/network/members)
|
10 | [](https://github.com/eugenehp/gatsby-source-medium-backup/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3Abug)
|
11 | [](https://github.com/eugenehp/gatsby-source-medium-backup/issues)
|
12 | [](https://github.com/eugenehp/gatsby-source-medium-backup/pulls)
|
13 |
|
14 | [](https://packagephobia.com/result?p=gatsby-source-medium-backup)
|
15 | [](https://bundlephobia.com/result?p=gatsby-source-medium-backup@0.0.1)
|
16 |
|
17 | Gatsby plugin to import your medium posts from a backup as markdown files.
|
18 |
|
19 | ## Installation
|
20 |
|
21 | We assume you've already [created gatsby website](https://www.gatsbyjs.com/docs/tutorial/part-zero/#create-a-gatsby-site) using command like this:
|
22 |
|
23 | ```shell
|
24 | gatsby new example https://github.com/gatsbyjs/gatsby-starter-hello-world
|
25 | ```
|
26 |
|
27 | ### Install dependencies
|
28 |
|
29 | ```shell
|
30 | cd example
|
31 | npm i -s gatsby-source-filesystem gatsby-transformer-remark gatsby-source-medium-backup
|
32 | ```
|
33 |
|
34 | ### Configure your gatsby plugins
|
35 |
|
36 | Go to `gatsby-config.js` and configure folder for your processed markdown pages first:
|
37 |
|
38 | ```javascript
|
39 | const markdownPages = `${__dirname}/src/markdown-pages`
|
40 | ```
|
41 |
|
42 | Then inside the `plugins` section add `gatsby-source-medium-backup` first and specify location of your medium backfile inside `source`:
|
43 |
|
44 | ```javascript
|
45 | {
|
46 | resolve: 'gatsby-source-medium-backup',
|
47 | options: {
|
48 | source: `${__dirname}/medium-export.zip`,
|
49 | destination: markdownPages,
|
50 | },
|
51 | },
|
52 | ```
|
53 |
|
54 | Add markdown generation **after** above plugin!
|
55 |
|
56 | ```javascript
|
57 | // markdown
|
58 | {
|
59 | resolve: `gatsby-source-filesystem`,
|
60 | options: {
|
61 | path: markdownPages,
|
62 | name: `markdown-pages`,
|
63 | //prefix: 'blog' // optional: prefix all slugs
|
64 | h1h2: true, // optional: convert all h3 and h4 to h1 and h2
|
65 | // h2h3: true, // optional: convert all h3 and h4 to h2 and h3
|
66 | },
|
67 | },
|
68 | `gatsby-transformer-remark`,
|
69 | ```
|
70 |
|
71 | ### Download your medium archive
|
72 |
|
73 | [Here](https://help.medium.com/hc/en-us/articles/115004745787-Download-your-information)'s official guide from Medium.
|
74 |
|
75 | 1. On your homepage, click on your profile picture and click Settings.
|
76 | 2. Scroll down to the Download your information section.
|
77 | 3. Click Download . zip and confirm by clicking Export.
|
78 | 4. A link to download your archive will be sent to you by email when it is finished.
|
79 |
|
80 | ### Configure your gatsby blog posts generation
|
81 |
|
82 | This section essentially follows original guideline for adding markdown pages [here](https://www.gatsbyjs.com/docs/how-to/routing/adding-markdown-pages/)
|
83 |
|
84 | 1. Create [`./src/templates/blogTemplate.js`](./src/templates/blogTemplate.js), which will be used as a page template for your blog posts.
|
85 | 2. Configure your [`./gatsby-node.js`](./gatsby-node.js) to generate blog posts using markdown files during the build time.
|
86 |
|
87 | ### Now run your gatsby
|
88 |
|
89 | ```shell
|
90 | cd example
|
91 | gatsby develop
|
92 | ```
|
93 |
|
94 | Navigate to [http://localhost:8000/404](http://localhost:8000/404) and you'll see your markdown pages generated.
|
95 |
|
96 | <img width="900" alt="Screen Shot 2021-04-08 at 20 26 36" src="https://user-images.githubusercontent.com/1857263/114124179-b8f62980-98a8-11eb-890c-94feb7eeedcf.png">
|
97 |
|
98 |
|
99 | ## Troubleshooting
|
100 |
|
101 | 1. Make sure to put absolute path for your medium archive.
|
102 |
|
103 | 2. This plugin generate following metadata for each post:
|
104 |
|
105 | ```json
|
106 | {
|
107 | "title": "How to build a react-native plugin in 2021",
|
108 | "author": "Eugene Hauptmann",
|
109 | "authorLink": "https://medium.com/@eugenehauptmann",
|
110 | "canonical": "https://medium.com/@eugenehauptmann/how-to-build-a-react-native-plugin-in-2021-60704edc0c28",
|
111 | "timestamp": "2021-04-06T00:58:51.984Z",
|
112 | "exportDate": "April 6, 2021"
|
113 | }
|
114 | ```
|
115 |
|
116 | ## Sponsorship
|
117 |
|
118 | Thank you to our sponsors:
|
119 |
|
120 | [<img width="300px" src="https://user-images.githubusercontent.com/1857263/114124204-c4e1eb80-98a8-11eb-80ab-64683c24bbc5.png" alt="Reactive Lions™" target="_blank">](https://www.reactivelions.com)
|
121 |
|
122 | ## License
|
123 |
|
124 | [MIT](./LICENSE)
|
125 |
|
126 | Copyright (c) 2021 Eugene Hauptmann
|