diff --git a/index.js b/index.js index f66f719..5350108 100755 --- a/index.js +++ b/index.js @@ -5,10 +5,11 @@ const path = require('path') const router = require('koa-router')() const views = require('koa-views') -const home = require('./routes/home') -const thread = require('./routes/thread') const author = require('./routes/author') const hashtag = require('./routes/hashtag') +const home = require('./routes/home') +const profile = require('./routes/profile') +const thread = require('./routes/thread') const app = module.exports = new Koa() @@ -16,13 +17,14 @@ app.use(views(path.join(__dirname, 'views'), { map: { html: 'ejs' } })) -app.use(require('koa-static')('static')) +app.use(require('koa-static')('public')) router .get('/', home) - .get('/thread/:id', thread) .get('/author/:id', author) .get('/hashtag/:id', hashtag) + .get('/profile/', profile) + .get('/thread/:id', thread) app.use(router.routes()) diff --git a/static/style.css b/public/style.css similarity index 71% rename from static/style.css rename to public/style.css index fa0955b..80d829d 100644 --- a/static/style.css +++ b/public/style.css @@ -33,6 +33,16 @@ h1, h2, h3, h4, h5, h6 { max-width: 100%; } +.message > :first-child { + margin-top: 0; + padding-top: 0; +} + +.message > :last-child { + margin-bottom: 0; + padding-bottom: 0; +} + .message code { color: hsl(330, 75%, 50%) } @@ -51,7 +61,7 @@ h1, h2, h3, h4, h5, h6 { .message { background: #fff; padding: 1.5rem; - margin: 0.75rem 0; + margin: 1rem 0; border-radius: 2px; border: 1px solid #ddd; @@ -75,7 +85,36 @@ h1, h2, h3, h4, h5, h6 { } .message > footer > a { color: #888; - margin-right: 0.5rem; + margin-right: 1rem; text-decoration: none; font-weight: bold; } + +nav a { + color: #888; + margin-right: 1rem; + text-decoration: none; + font-weight: bold; +} + +.profile { + margin-top: 1rem; + display: flex; + margin-bottom: 1rem; +} + +.profile > img, .profile > h1 { + display: inline-block; +} + +.profile > img { + width: 4rem; + height: 4rem; + margin-right: 1rem; + border-radius: 2px; +} + + +ul { + padding-left: 1rem; +} diff --git a/routes/author.js b/routes/author.js index 9086d15..0f5979f 100644 --- a/routes/author.js +++ b/routes/author.js @@ -22,6 +22,18 @@ module.exports = async function (ctx) { } ) + const avatarMsg = await cooler.get( + ssb.about.socialValue, { key: 'image', + dest: ctx.params.id + } + ) + + const avatarId = avatarMsg != null && typeof avatarMsg.link === 'string' + ? avatarMsg.link + : avatarMsg + + const avatarUrl = `http://localhost:8989/blobs/get/${avatarId}` + const description = renderMd(rawDescription) var msgSource = await cooler.read( @@ -50,5 +62,5 @@ module.exports = async function (ctx) { const msgs = await Promise.all(rawMsgs.map(renderMsg(ssb))) - await ctx.render('author', { msgs, name, description }) + await ctx.render('author', { msgs, name, description, avatarUrl }) } diff --git a/routes/profile.js b/routes/profile.js new file mode 100644 index 0000000..aea9cd1 --- /dev/null +++ b/routes/profile.js @@ -0,0 +1,9 @@ +const cooler = require('../lib/cooler') +const author = require('./author') + +module.exports = async function (ctx) { + const ssb = await cooler.connect() + const whoami = await cooler.get(ssb.whoami) + ctx.params.id = whoami.id + await author(ctx) +} diff --git a/views/author.html b/views/author.html index 26849ae..867136a 100644 --- a/views/author.html +++ b/views/author.html @@ -1,8 +1,16 @@ <%- include('partials/header.html'); %> -
null
\n') { %> + +<% } %> <%- include('feed.html', { msgs }); %> diff --git a/views/partials/header.html b/views/partials/header.html index eaa1647..621a963 100644 --- a/views/partials/header.html +++ b/views/partials/header.html @@ -5,5 +5,8 @@ - home +