Giter Site home page Giter Site logo

devtogo's Introduction

πŸ‘©πŸ½β€πŸ’»πŸŽ’

devtogo

a dev.to tool for the road🧳


devtogo is a cli for publishing offline markdown files to dev.to.

πŸ’Ύ install

🍻 Homebrew (osx)

$ brew install softprops/tools/devtogo

πŸ“¦ Cargo

$ cargo install devtogo

🚒 GitHub Releases

Using a version from this repo's GitHub Releases page, substitute a VERSION below with a valid release version

$ cd $HOME/bin
$ export VERSION=v0.1.0
$ curl -L "https://github.com/softprops/devtogo/releases/download/${VERSION}/devtogo-$(uname -s)-$(uname -m).tar.gz" \
  | tar -xz -C ~/bin

πŸ€Έβ€β™‚οΈ usage

devtogo is a cli for publishing offline markdown files to dev.to. These files follow the same formatting rules documented in dev.to's editor guide.

At a bare minimum you'll want to declare a title in a frontmatter section of your markdown file.

---
title: my very first post
---

# hello everybody

To get started, you will first need to export an DEVTO_API_KEY environment variable. You can generate yours πŸ‘‰here

$ export DEVTO_API_KEY='som3R@ndOmAp1K3y'

The most basic usage is to run the program inside the directory containing your target article content

$ devtogo

This will scan the current working directory for articles: markdown documents containing frontmatter describing metadata about the article. devtogo uses the title frontmatter field as a unique identifier to compare existing remote content.

When it can't resolve an article by title, it uploads it assuming it's a new article. When it can, it compares local and remote content and uploads local copy if the content of the local copy differs.

you can use the published frontmatter to indicate if and when an article should be published by default articles are saved as drafts only you can see. Setting published to true will publish articles. If you do this by accident you can set published back to false to revert a published an article if needed

To be more explicit you can provide a source argument which provides a path where content is stored.

$ devtogo --source path/to/content

You can also experiment without actually posting your content using the --dryrun flag. This will perform all operations except for uploading your content. This may be useful for validating your content.

$ devto --dryrun

You can always review the posts uploaded in your dev.to dashboard online

Doug Tangren (softprops) 2020

devtogo's People

Contributors

davidmaceachern avatar softprops avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

devtogo's Issues

add filter for file ext

because running in any random dir will inevitably result in something like this

$ devtogo --dryrun                                                                                                                                         
Error: stream did not contain valid UTF-8

improve api error ux

when making a request with a bad or invalid api key you get a very non-useful error message

DEVTO_API_KEY=badvalue devtogo -s posts
Error: error decoding response body: invalid type: map, expected a sequence at line 1 column 0

Caused by:
    invalid type: map, expected a sequence at line 1 column 0

lets fix that

Fails to POST article

Steps to recreate

  1. Install with Cargo, or clone main and compile locally with cargo build.
  2. Export a key for a Dev.to account, an account that contains an article that was created on Dev.to Web version.
  3. Navigate to a directory that contains 4 articles, 3 that have previously been uploaded to Dev.to and 1 new article.
  4. Run devtogo.
  5. Expect Dev.to to return a 422 error.
Dev.to error: 422 {"error":"article param must be a JSON object. You provided article as NilClass","status":422}

Investigation

Have traced it to the POST operation and have removed the send and await from the POST request.

        async move {
            let resp = client
                .post("https://dev.to/api/articles")
                .header("api-key", api_key.as_str())
                .json(&CreateArticleInput {
                    body_markdown: content,
                });
            println!("{:?}", resp);
            Ok(())
            }

Which when printing returns the following without the article param.

RequestBuilder { method: POST, url: "https://dev.to/api/articles", headers: {"api-key": "API_KEY", "content-type": "application/json"} }

It looks like the POST is being made with no value for the article which is why Dev.to throws a nilclass error which is what Ruby does when a value is nil or doesn't exist.

When printing the content that is to be converted by the reqwest json feature

        let content2 = content.clone();
        println!("{}", content2);

It outputs the content without an issue.

---
title: Hello, World!
published: false
tags: discuss, help
series: Hello series
canonical_url: https://example.com/blog/hello
---

Hello DEV, this is my first post

Ideas about what to try next

  • Check whether content.clone() is an issue
  • Check Reqwest and the json feature maybe they have issues?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.