GithubHelp home page GithubHelp logo

nghilevi / m101js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielabar/m101js

0.0 1.0 0.0 1.88 MB

Weekly course notes from MongoDB University M101JS: MongoDB for Node.js Developers

Home Page: http://danielabar.github.io/m101js

License: MIT License

JavaScript 9.31% ApacheConf 24.21% HTML 64.68% CSS 1.80%

m101js's Introduction

m101js

Weekly course notes from MongoDB University M101JS: MongoDB for Node.js Developers

About

This project is built using the Yeoman generator for AngularJS and deployed to github pages. This presents a slight challenge for deployment because GitHub wants to host the root of the "master" branch as the doc root, whereas yeoman wants your docroot to be hosted out of the "dist/". The solution to this is explained here and here.

Relative Links

Another challenge is getting the Angular generated relative links to work. For example, when developing locally using grunt serve, the root url is:

http://127.0.0.1:9000/#/

Now let's say you have a link such as:

<a href="/#/awesome">My Awesome Link</a>

Locally, it gets generated as:

http://127.0.0.1:9000/#/awesome

However, once the dist dir is pushed to gh-pages branch, the root url will be something like:

http://danielabar.github.io/m101js/#/

And the awesome link will be generated as:

http://danielabar.github.io/#/awesome

This is a problem because it won't be found. For Github Pages, the url should actually be:

http://danielabar.github.io/m101js/#/awesome

The solution I came up with is to use grunt-text-replace to modify all urls with /# to start with /m101js. The grunt task uses a regex to identify the urls, and a convenient callback function to do the replacement. It looks something like this:

replace: {
  dist: {
    src: ['<%= yeoman.dist %>/views/main.html'],
    overwrite: true,
    replacements: [
      {
        from: /\/#\//g,
        to: function(matchedWord) {
          return '/m101js' + matchedWord;
        }
      }
    ]
  }
    }

An improvement could be to replace m101js with a project variable to make the solution more generic. But overall, this feels a litle hack-ey, if anyone has a better solution, let me know.

Development

Startup grunt in preview mode

grunt serve

Make changes, for example, to add a new route to week3 course notes

yo angular:route week3

Add content to week3.html and link to it from main.html. Changes are automatically reflected in browser via grunt watch task.

Build

Run the grunt build task

grunt

If it succeeds, you're ready to deploy.

Deploy

The overall project is pushed to master branch, and git subtree is used to push the dist dir to gh-pages branch.

git add .
git commit -m "your message"
git push origin master
git subtree push --prefix dist origin gh-pages

m101js's People

Contributors

danielabar avatar

Watchers

nghi avatar

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.