{"id":16641980,"url":"https://github.com/artskydj/noddity-render-dom","last_synced_at":"2025-04-05T01:25:48.046Z","repository":{"id":65459867,"uuid":"42553879","full_name":"ArtskydJ/noddity-render-dom","owner":"ArtskydJ","description":"Render Noddity posts to the DOM","archived":false,"fork":false,"pushed_at":"2017-01-10T01:18:00.000Z","size":88,"stargazers_count":1,"open_issues_count":5,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T05:17:05.650Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArtskydJ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-15T23:59:24.000Z","updated_at":"2017-01-10T01:17:58.000Z","dependencies_parsed_at":"2023-01-24T14:25:11.620Z","dependency_job_id":null,"html_url":"https://github.com/ArtskydJ/noddity-render-dom","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fnoddity-render-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fnoddity-render-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fnoddity-render-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fnoddity-render-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtskydJ","download_url":"https://codeload.github.com/ArtskydJ/noddity-render-dom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247273998,"owners_count":20912029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T07:48:28.713Z","updated_at":"2025-04-05T01:25:48.031Z","avatar_url":"https://github.com/ArtskydJ.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# noddity-render-dom\r\n\r\n\u003e Render Noddity posts to the DOM\r\n\r\n[![Build Status](https://travis-ci.org/ArtskydJ/noddity-render-dom.svg?branch=master)](https://travis-ci.org/ArtskydJ/noddity-render-dom)\r\n\r\n# example\r\n\r\n```js\r\nvar renderDom = require('noddity-render-dom')\r\nvar Butler = require('noddity-butler')\r\nvar Linkifier = require('noddity-linkifier')\r\nvar LevelJs = require('level-js')\r\n\r\nvar db = new LevelJs('noddity-posts-db')\r\nvar butler = new Butler('http://example.com/blogfiles/', db)\r\nvar linkifier = new Linkifier('#/myposts/')\r\n\r\nvar options = {\r\n\tbutler: butler,\r\n\tlinkifier: linkifier,\r\n\tel: 'body',\r\n\tdata: {\r\n\t\tconfig: {\r\n\t\t\tconfigProperty: 'configValue'\r\n\t\t},\r\n\t\tarbitraryValue: 'lol'\r\n\t}\r\n}\r\n\r\nrenderDom('post-template.html', options, function (err, setCurrent) {\r\n\tsetCurrent('my-awesome-post.md', function (err) {\r\n\t\tif (err) throw err // 404\r\n\t})\r\n})\r\n```\r\n\r\n# api\r\n\r\n```js\r\nvar renderDom = require('noddity-render-dom')\r\n```\r\n\r\n## `renderDom(post, options, cb)`\r\n\r\n- `post`: a Noddity post object or a post filename\r\n- `options`: all the other arguments\r\n\t- `butler`: a [Noddity Butler](https://www.npmjs.com/package/noddity-butler)\r\n\t- `linkifier`: a [Noddity Linkifier](https://www.npmjs.com/package/noddity-linkifier)\r\n\t- `el`: a selector string of the element to which the Ractive object will be bound. *Optional*\r\n\t- `data`: any properties on the `data` object will be made available to the templates. *Optional*\r\n- `cb(err, setCurrent)`: a function to be called when the first render is finished.\r\n\r\n## `setCurrent(post, [data,] [cb])`\r\n\r\n`setCurrent` is a function/event emitter.\r\n\r\nCall the function to change the current post to a different post.\r\n\r\n- `post`: a Noddity post object, or a post filename\r\n- `data`: any properties on the `data` object will be made available to the templates. *Optional*\r\n- `cb(err)`: an optional function that is called when the current post is set or a fatal error occurs. *Optional*\r\n\r\n### events\r\n\r\n- `error(err)` is emitted on non-fatal errors, e.g. an embedded template not loading\r\n\t- `err` is an Error object\r\n\r\n```js\r\nsetCurrent('my-post.md', function (err) {\r\n\tif (err) throw err // Could not set 'my-post.md' to be the current post\r\n})\r\n\r\nsetCurrent.on('error', function (err) {\r\n\tconsole.error(err) // Probably an embedded template didn't load\r\n})\r\n```\r\n\r\n# values accessible in ractive expressions\r\n\r\n- `postList`: an array of post objects that have dates, ordered by date descending.  Metadata is accessible on the object iself without having to use the `metadata` property\r\n- `posts`: an object whose keys are the post file names, and whose value is the post object.  Right now the keys all have periods `.` stripped from them due to an issue with Ractive\r\n- `removeDots`: a function that takes a string as input and returns a version with dots `.` removed\r\n- `current`: the file name of the currently displayed post (the one specified in the url).  Also a partial of the current post (set by `setCurrent()`). Can be accessed by doing `{{\u003ecurrent}}` or `{{{html}}}`\r\n- `metadata`: an object of the metadata of the current post. E.g. `{{metadata.title}}` accesses the title of the current post, even if it is in an embedded template.\r\n- Metadata values of the template are exposed. (Except in the root post, where the current post's metadata is exposed). E.g. `{{title}}` accesses the title of the current.\r\n\r\n### ractive expressions example\r\n\r\nroot.html\r\n```\r\n\u003ch1\u003e{{title}}\u003c/h1\u003e\r\n\u003carticle\u003e\r\n\t{{\u003ecurrent}}\r\n\u003c/article\u003e\r\nWritten by {{author}} on {{date.toDateString()}}.\r\n```\r\n\r\npost1.md\r\n```\r\ntitle: welcome\r\ndate: 2015-10-30\r\nauthor: Joseph\r\n\r\nHey, thanks for visiting my blog!!!\r\n\r\n::embed.md::\r\n```\r\n\r\nembed.md\r\n```\r\ntitle: embed\r\n\r\nThe title is: {{metadata.title}}\r\nMy title is: {{title}}\r\n```\r\n\r\nSet root.html to be the root, and post1.md to be the current post:\r\n```js\r\nrenderDom('root.html', options, function (err, setCurrent) {\r\n\tsetCurrent('post1.md', function (err) {\r\n\t\tif (err) throw err // 404\r\n\t})\r\n})\r\n```\r\n\r\nEnd up with something like:\r\n```\r\n\u003ch1\u003ewelcome\u003c/h1\u003e\r\n\u003carticle\u003e\r\n\tHey thanks for visiting my blog!!!\r\n\r\n\tThe title is: welcome\r\n\tMy title is: embed\r\n\u003c/article\u003e\r\nWritten by Joseph on Fri Oct 30 2015\r\n```\r\n\r\n# license\r\n\r\n[VOL](http://veryopenlicense.com)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartskydj%2Fnoddity-render-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartskydj%2Fnoddity-render-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartskydj%2Fnoddity-render-dom/lists"}