shipshapecode / ember-journal

A blogging engine for Ember apps
MIT License
2 stars 0 forks source link

Integrate with markdown #3

Open RobbieTheWagner opened 7 years ago

RobbieTheWagner commented 7 years ago

Should investigate using https://github.com/willviles/ember-cli-markdown-resolver to pull in markdown files, rather than pulling data from the API.

willviles commented 7 years ago

I think this should be fairly simple to achieve. I'd do it through a series of blueprints to give the user flexibility to move their content source folders, extend routes and customise templates.

1) Ensure ember-cli-markdown-resolver is installed in addon's afterInstall. Add Ember CLI Markdown Resolver config to application and add the default markdown content folder with a hello-world.md, perhaps at app/posts.

2) Add post route definitions to app's router. Something like this:

this.route('posts', function() {
  this.route('single', { path: '/*path' });
});

3) Add routes, perhaps extending some kind of route mixin:

// Posts index
export default Route.extend(
  EmberJournalPostIndexRouteMixin, {
    // Which would equate to...
    markdownResolver: inject(),

    model() {
      return get(this, 'markdownResolver.files'); // Gets an array of all files. 
      // At the moment, this returns all files across all markdown folders, 
      // but I'm going to add some sort of file querying interface to 
      // Ember CLI Markdown Resolver in the near future...
    }
  }
);
// Posts single
export default Route.extend(
  EmberJournalPostRouteMixin, {
    // Which would equate to...
    markdownResolver: inject(),

    model({ path }) {
      return get(this, 'markdownResolver').file('posts', path);
    }
  }
);

4) Add some default templates to posts.hbs, posts/index.hbs and posts/single.hbs.

To build in some fairly common blogging functionality such as prev/next post, we could look at building that output into Broccoli Markdown Resolver. I've also considered moving sorting functionality into the Broccoli plugin, which would improve runtime performance.

As for parsing the markdown content, I'm using Ember CLI Showdown on https://willviles.github.io/ember-cli-markdown-resolver/, with a custom config allowing Ember Code Prettify to render code snippets.

What do you think of this approach?