diff --git a/docs/contributing.md b/docs/contributing.md index cd18263..6816610 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -4,18 +4,27 @@ Hey, welcome! This project is still very experimental so I won't make any promises about the future architechture, but today it's pretty simple: ``` -src: you are here! -├── assets: static resources like CSS and images -└── routes: URL handlers that integrate views with models - ├── models: abstractions for working with the database - │   └── lib: code shared by models (like Markdown rendering) - └── views: page renderers that receive data and output HTML - └── components: shared components that are reused across pages +index.js: take command-line arguments and give an application over HTTP + └── src: take HTTP requests and give an asset or a dynamic HTML page + ├── assets: give static assets like CSS and images + └── pages: take parameters and give an HTML page that with inline data + ├── models: give an abstract interface for interacting with data + │   └── lib: give database driver, Markdown renderer, etc. + └── views: take data and give an HTML page + └── components: take data and give HTML components (sub-views) ``` I'd really appreciate any issues or pull requests on GitHub. Please let me know if there's anything I can do to help support your work on this project. +## Debugging + +Debugging is never going to be easy, but the debug script helps a bit. You can +use `oasis --debug` or debug the source with `npm run debug` / `yarn debug`. +Please feel free to add `debug()` statements to the code wherever you think +they might be helpful -- as long as we aren't using them hundreds of times per +second I don't think they'll have a noticeable effect on performance. + ## Experiments ### Always forward, never back @@ -96,3 +105,4 @@ the templates to use hyperaxe. Oops. I think hyperaxe has a cooler name anyway. [dep-graph]: https://en.wikipedia.org/wiki/Dependency_graph [koa-blog]: https://github.com/koajs/examples/blob/1fd531698cc5ef21a61b627058ad0aafe9e55360/blog/lib/render.js#L13 [hyperaxe-gh]: https://github.com/ungoldman/hyperaxe +[debug-gh]: https://github.com/visionmedia/debug diff --git a/package.json b/package.json index 7baa2ed..e1c299e 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ }, "scripts": { "start": "node index.js", - "dev": "nodemon index.js --debug", + "debug": "nodemon --inspect index.js --debug", "test": "test/script.sh", "preversion": "test/script.sh" } diff --git a/src/app.js b/src/app.js index f0996cc..afee186 100644 --- a/src/app.js +++ b/src/app.js @@ -13,15 +13,15 @@ module.exports = (config) => { const debug = require('debug')('oasis') const ssbRef = require('ssb-ref') - const author = require('./routes/author') - const hashtag = require('./routes/hashtag') - const home = require('./routes/home') - const profile = require('./routes/profile') - const raw = require('./routes/raw') - const thread = require('./routes/thread') - const like = require('./routes/like') - const status = require('./routes/status') - const highlight = require('./routes/highlight') + const author = require('./pages/author') + const hashtag = require('./pages/hashtag') + const home = require('./pages/home') + const profile = require('./pages/profile') + const raw = require('./pages/raw') + const thread = require('./pages/thread') + const like = require('./pages/like') + const status = require('./pages/status') + const highlight = require('./pages/highlight') const assets = new Koa() assets.use(koaStatic(path.join(__dirname, 'assets'))) @@ -52,6 +52,7 @@ module.exports = (config) => { }) .get('/highlight/:style', (ctx) => { const { style } = ctx.params + ctx.type = 'text/css' ctx.body = highlight(style) }) .get('/profile/', async (ctx) => { diff --git a/src/assets/style.css b/src/assets/style.css index e8ba958..5036a24 100644 --- a/src/assets/style.css +++ b/src/assets/style.css @@ -93,10 +93,11 @@ pre { word-wrap: break-word; } -.message > header { +.message > header.metadata { height: 1.5rem; display: flex; } + .message > header > a > .avatar { width: 1.5rem; height: 1.5rem; diff --git a/src/routes/author.js b/src/pages/author.js similarity index 100% rename from src/routes/author.js rename to src/pages/author.js diff --git a/src/routes/hashtag.js b/src/pages/hashtag.js similarity index 100% rename from src/routes/hashtag.js rename to src/pages/hashtag.js diff --git a/src/routes/highlight.js b/src/pages/highlight.js similarity index 65% rename from src/routes/highlight.js rename to src/pages/highlight.js index ca7cdfd..7cf03fb 100644 --- a/src/routes/highlight.js +++ b/src/pages/highlight.js @@ -2,8 +2,5 @@ const requireStyle = require('require-style') module.exports = function (style) { const filePath = `highlight.js/styles/${style}` - return { - body: requireStyle(filePath), - type: 'text/css' - } + return requireStyle(filePath) } diff --git a/src/routes/home.js b/src/pages/home.js similarity index 100% rename from src/routes/home.js rename to src/pages/home.js diff --git a/src/routes/like.js b/src/pages/like.js similarity index 100% rename from src/routes/like.js rename to src/pages/like.js diff --git a/src/routes/models/about.js b/src/pages/models/about.js similarity index 100% rename from src/routes/models/about.js rename to src/pages/models/about.js diff --git a/src/routes/models/lib/configure.js b/src/pages/models/lib/configure.js similarity index 100% rename from src/routes/models/lib/configure.js rename to src/pages/models/lib/configure.js diff --git a/src/routes/models/lib/cooler.js b/src/pages/models/lib/cooler.js similarity index 100% rename from src/routes/models/lib/cooler.js rename to src/pages/models/lib/cooler.js diff --git a/src/routes/models/lib/markdown.js b/src/pages/models/lib/markdown.js similarity index 100% rename from src/routes/models/lib/markdown.js rename to src/pages/models/lib/markdown.js diff --git a/src/routes/models/meta.js b/src/pages/models/meta.js similarity index 100% rename from src/routes/models/meta.js rename to src/pages/models/meta.js diff --git a/src/routes/models/post.js b/src/pages/models/post.js similarity index 100% rename from src/routes/models/post.js rename to src/pages/models/post.js diff --git a/src/routes/models/vote.js b/src/pages/models/vote.js similarity index 100% rename from src/routes/models/vote.js rename to src/pages/models/vote.js diff --git a/src/routes/profile.js b/src/pages/profile.js similarity index 100% rename from src/routes/profile.js rename to src/pages/profile.js diff --git a/src/routes/raw.js b/src/pages/raw.js similarity index 100% rename from src/routes/raw.js rename to src/pages/raw.js diff --git a/src/routes/status.js b/src/pages/status.js similarity index 100% rename from src/routes/status.js rename to src/pages/status.js diff --git a/src/routes/thread.js b/src/pages/thread.js similarity index 100% rename from src/routes/thread.js rename to src/pages/thread.js diff --git a/src/routes/views/author.js b/src/pages/views/author.js similarity index 73% rename from src/routes/views/author.js rename to src/pages/views/author.js index 54c8e01..2b30f68 100644 --- a/src/routes/views/author.js +++ b/src/pages/views/author.js @@ -2,6 +2,7 @@ const template = require('./components/template') const post = require('./components/post') const { + article, header, img, h1, @@ -9,20 +10,18 @@ const { } = require('hyperaxe') module.exports = ({ avatarUrl, name, description, messages }) => { - const authorHeader = + const prefix = section({ class: 'message' }, header({ class: 'profile' }, img({ class: 'avatar', src: avatarUrl }), h1(name) - ) - - const authorDescription = + ), description !== '

null

\n' - ? section({ class: 'message', innerHTML: description }) + ? article({ innerHTML: description }) : null + ) return template( - authorHeader, - authorDescription, + prefix, messages.map(msg => post({ msg }) ) diff --git a/src/routes/views/components/post.js b/src/pages/views/components/post.js similarity index 98% rename from src/routes/views/components/post.js rename to src/pages/views/components/post.js index c59f9c6..78d40fd 100644 --- a/src/routes/views/components/post.js +++ b/src/pages/views/components/post.js @@ -66,7 +66,7 @@ module.exports = ({ msg }) => { class: messageClasses.join(' '), style: `margin-left: ${depth * 1.5}rem` }, - header( + header({ class: 'metadata' }, a({ href: url.author }, img({ class: 'avatar', src: url.avatar, alt: 'profile image' }) ), diff --git a/src/routes/views/components/template.js b/src/pages/views/components/template.js similarity index 100% rename from src/routes/views/components/template.js rename to src/pages/views/components/template.js diff --git a/src/routes/views/list.js b/src/pages/views/list.js similarity index 100% rename from src/routes/views/list.js rename to src/pages/views/list.js diff --git a/src/routes/views/status.js b/src/pages/views/status.js similarity index 100% rename from src/routes/views/status.js rename to src/pages/views/status.js