Giter Club home page Giter Club logo

samatha's Introduction

Samatha v0.4.0

Copyright David Springate 2013 (CC BY 3.0)

@datajujitsu

Samatha is an R package for quickly building Github-ready static sites in R. It contains a simple, functional-style DSL for rendering HTML, an engine for compilation of static websites as you build them and a development web-server for viewing your sites of line before you deploy.

This project is still in active development. Feel free to contact me with any issues/bugs/suggestions

The Static site engine uses the Samatha DSL to build layout templates which it then combines with content to generate individual pages. templates are written as a nested R expression, with no need for extenal templating systems. There are two ways to build pages:

  1. Pages are written entirely in the Samatha DSL and compiled with a layout file. This is ideal for introductiory pages and index pages.
  2. Blog posts are written in .Rmd format, which is then converted to md using knitr and then to html using markdown. Posts are then rendered within the layout for that post.

The Samatha engine samatha() now functions as expected. It compiles your site and then updates in real time according to the following rules:

  • if a layout file is altered
    • The whole site is re-built
      • pages compiled to html
      • posts knitted and then compiled to html
      • rss and tag files generated
  • if any page/post source files are newer than their corresponding html or if the html doesn't exist:
    • Pages in question are knitted and/or re-compiled
    • rss and tag files re-generated
  • Any html files without a corresponding source are deleted

Extra features:

  • simple wrapper functions for including snippet files containing md or html/js (e.g. for external comments site code and analytics)
  • You can include tags for posts in the first line of a post .Rmd file by starting the line with %. All words on the rest of the line are coerced to tags and included in the RSS file.
  • Automatically generates an RSS file at the top level of your site with global paths and per item tags, content and full links to images etc. Tags/categroies for the whole site can be set in the template/config/config.R file. This is the format required by Rbloggers for blog submission.
  • The rss.category.feeds variable in the config.R file can be used to add extra rss feeds for specific categories. For example, R Bloggers require that all posts sent to them only concern R. You can therefore set rss.category.feeds = c(R) and Samatha will produce another rss feed just with your R content (matching tags for "R") and put it in site/site/tags/R.xml. You can then send this link to Rbloggers and be feee to publish on other subjects, knowing only R content will go to Rbloggers.
  • Helper functions for building lists of tags and lists of posts

Sites are created with the following structure:

  • basename
    • template the source for your site
      • layouts layout templates for pages and posts
      • config contains config.R file for rss, tags, post layoutss and figure path
      • pages Content of pages built with the Samatha dsl
      • posts Rmd files of blog posts
      • resources html/js/md snippets
    • basename the compiled site. Copy the contents to a git repo to have a functioning site
      • css Put your css files (e.g. from twitter bootstrap) here
      • img plots from knitted Rmd are automatically placed here
      • pages html for site pages
      • posts
      • tags

Examples

My personal blog was built using Samatha, twitter bootstrap and Github pages. I used the Readable theme. See here for the file structure of a Samatha site.

This gist Gives code to quickly setting up an example site.

Install

You should be able to install the current version of Samatha with devtools:

# check install_github()
require(devtools)
install_github("samatha", "DASpringate")

Simple Startup

library(samatha)
site <- "/dir1/dir2/dirSite"
skeleton(site)
setup_example_site(site)

samatha(site, rss = FALSE, initial = TRUE)
samatha(site, rss = FALSE, initial = TRUE)

run.server(site)  # open browser to localhost:8000 to see the site

Documentation

I'm still working on it!

Glaring ommisions (To be fixed very soon):

  • Automatic creation of config files and example default templates. For now, check my site structure for setup details.

samatha's People

Contributors

daspringate avatar rmflight avatar rflight79 avatar

Watchers

James Cloos avatar  avatar

samatha's Issues

similarity analysis

Would be really cool to build a "if you liked this, you might also like" section using the tm package and some sort of LSA or plain cosine similarity.

[this][http://www.r-bloggers.com/build-a-search-engine-in-20-minutes-or-less/] seems to be a nice guide for building a search engine, which is similar.

If we did this, we would like to probably remove code blocks so that we are considering only the written word, or offer the option to remove code blocks or not to the user.

always update pages

Although posts don't need to be updated, the pages will almost always need to be updated each time something needs to be done. Posts, once generated they should be good, at least depending on the template.

Maybe have a variable called which.update that can be "all", "pages", "posts", and depending on it either everything gets updated, or just the pages, or just the posts??

put resources in extdata

Put all the materials for creating a skeleton site in extdata so that everything can be instantiated quickly, and we don't need to use devtools and load all to quickly create a new site.

Separate md generation from render.post

In my workflow, I commonly have blog posts that take a lot of work to run the Rmd part. So, if the md is newer than Rmd, there should be no reason to generate md, and we should have a function to generate md with the proper knitr settings, so I can gen md from Rmd separate from calling Samatha to generate the full site.

Render.post would then also check to see if md exists, and if it is newer than Rmd, and if so simply do the md to HTML part.

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.