downwrite

โœ๏ธ Markdown writing application that's down right, neat.

MIT License

Stars
103

Downwrite

About ๐Ÿค”๐Ÿฆ„๐ŸŽ‰

A place to write. โœ๏ธ

So the idea here was simple build a simple markdown writing application. Markdown is a huge deal and all the cool tools kept getting shut down and naively,I thought, how hard can this really be? ๐Ÿค”๐Ÿ“๐Ÿ“ฆ

So I've had poorly designed iterations of this thing for every year, on the year as one of these services got shut down. When Canvas shut down this last year, I started to get a little more serious about this idea. ๐Ÿ’ก โšก๐Ÿ”ญ

During planning out some of my quarterly goals at my last job I decided to go a little more full-stack with Node and start to really work through the process of building a microservice. Since I'm never really one to learning languages and frameworks in the abstract, I decided to take up Downwrite as an excuse to build those microservices. ๐Ÿ“ก๐Ÿ’ธ๐ŸŒŽ

Why Markdown ๐Ÿง๐Ÿคจ๐Ÿ“‹

Markdown is probably the most efficient and universal tool for conveying syntax, semantics and structure across platforms. โฌ‡๏ธ

Originally coined by John Gruber (Daring Fireball) it was originally conceived as a text to HTML and is the staple of static site generators, OSS as well as a fair amount of comment sections, notetaking applications or any documentation tool. ๐Ÿ› 

These shortcuts are almost as ubiquitous as cmd + b for bold or cmd + i for italics. โŒจ๏ธ

Bottomline: markdown is data. It is a method for describing semantics of data and is data itself.

Features โœจ๐Ÿ”ฅ๐Ÿš€

This is meant to be a simple writing application with some key features:

  • Write wherever you are in markdown
  • Share what you've written if you want
  • Upload a markdown file from your machine
  • Export to a static markdown file for your blog, etc.

Setup ๐Ÿ“ฒโณโš™๏ธ

This project uses Node (v12.18.x), TypeScript and pnpm.

brew cask install pnpm
pnpm install

Personally use fnm to manage my node versions.

fnm install
fnm use

Environment

To get started create an .env file in the root of your project with the following

SECRET_KEY="SECRET SECRETS ARE NO FUN"
CURRENT_DB_ADDRESS="127.0.0.1:27017/downwrite"

Client โšก๏ธ๐ŸฆŠ

Setup

Run in your terminal from the root of the project.

pnpm dev

Open http://localhost:3000 in your browser.

UI ๐Ÿ“

This is the client-side of the application, it uses Next.js and is a pretty stock implementation of how Next handles routing to different views. ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿคœ๐Ÿฆ‘๐Ÿคฏ

Downwrite needs to server side rendered to make sharing an entry as easy as possible. Next.js' data-fetching API makes it the perfect candidate. So when the page calls getServerSideProps() it fetches the data directly from the database (DB creditentials aren't exposed to the client build at all because of the bundling features inside Next ๐Ÿ˜) and for the initial render it has data available instead of a skeleton screen. ๐Ÿค–โ˜ ๏ธ๐Ÿ’€

For the Editor this project uses Draft.js and Draft.js Plugins. Markdown syntax is used inline and autogenerates the related rich text _hello_ becomes "hello" as you type.๐Ÿ’ปโŒจ๏ธ๐Ÿ”

For styles I just used the built-in CSS support in Next.js

Serverless Functions ๐ŸŒŽโœจ

To update the data, this project calls endpoints at /api/.... to enable this we're using Next'js API Routes. These are serverless functions so we don't need to keep a server or database connectioin running all the time, with serverless functions you're essentially calling the API on-demand.

This project also depends on MongoDB ๐Ÿ for data persistence, you should see this gist on how to setup MongoDB on your machine.

To authenticate we're using JWT to call the basic CRUD functions. Basically this is using a stateless auth model, more about that here. ๐Ÿ”

Related Documentation ๐Ÿ“š

Integration Testing ๐ŸŒˆ๐Ÿฆ๐Ÿ›

pnpm test

Info ๐Ÿ“๐Ÿงช

Short hand: page is just a representation of whatever the headless browser, Puppeteer has rendered at that given moment.

Using Puppeteer I write assertions like this:

describe("Feature", () => {
	it("does this thing", async () => {
		await page.waitForSelector("#selector");
		await page.click("#selector");
		await page.waitForSelector("#other-selector");
	});
});

This approach accomplishes two things:

  • Ensures if an await statement errors or catch() the block will cause a failure
  • Makes the test sequential and simpler to write

Related Documentation ๐Ÿ“š

Workflow ๐Ÿ‘ทโ€โ™€๏ธ๐Ÿšง

Working on this project it uses GitHub actions to run the tests and deploys using vercel for easy rollback and immutable deployments.

License โš–๏ธ๐Ÿ’ฃ๐Ÿ›กโš”๏ธ

MIT License

Copyright (c) 2022 Charlie Peters

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.