Mercurial > prosody-modules
comparison mod_http_index/mod_http_index.lua @ 1827:9376e870f0e1
mod_http_index: Move template out into a file and make it configurable
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 04 Sep 2015 00:23:46 +0200 |
| parents | ae2235d6c3f8 |
| children | 7953b7dde6e7 |
comparison
equal
deleted
inserted
replaced
| 1826:ae2235d6c3f8 | 1827:9376e870f0e1 |
|---|---|
| 1 local url = require"socket.url"; | 1 local url = require"socket.url"; |
| 2 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape); | 2 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape); |
| 3 | 3 |
| 4 module:depends"http"; | 4 module:depends"http"; |
| 5 | 5 |
| 6 -- TODO Move templates into files | 6 local base_template; |
| 7 local base_template = [[ | 7 do |
| 8 <!DOCTYPE html> | 8 local template_file = module:get_option_string(module.name .. "_template", module.name .. ".html"); |
| 9 <html> | 9 template_file = assert(module:load_resource(template_file)); |
| 10 <head> | 10 base_template = template_file:read("*a"); |
| 11 <meta charset="utf-8"> | 11 template_file:close(); |
| 12 <meta name="viewport" content="width=device-width, initial-scale=1"> | 12 end |
| 13 <meta name="generator" value="prosody/{prosody_version} mod_{mod_name}"> | |
| 14 <link rel="canonical" href="{canonical}"> | |
| 15 <title>{title}</title> | |
| 16 <style> | |
| 17 body{background-color:#eeeeec;margin:1ex 0;padding-bottom:3em;font-family:Arial,Helvetica,sans-serif;} | |
| 18 header,footer{margin:1ex 1em;} | |
| 19 footer{font-size:smaller;color:#babdb6;} | |
| 20 .content{background-color:white;padding:1em;list-style-position:inside;} | |
| 21 nav{font-size:large;margin:1ex 1ex;clear:both;line-height:1.5em;} | |
| 22 nav a{padding: 1ex;text-decoration:none;} | |
| 23 @media screen and (min-width: 460px) { | |
| 24 nav{font-size:x-large;margin:1ex 1em;} | |
| 25 } | |
| 26 a:link,a:visited{color:#2e3436;text-decoration:none;} | |
| 27 a:link:hover,a:visited:hover{color:#3465a4;} | |
| 28 ul{padding:0;} | |
| 29 li{list-style:none;} | |
| 30 hr{visibility:hidden;clear:both;} | |
| 31 br{clear:both;} | |
| 32 li:hover time{opacity:1;} | |
| 33 </style> | |
| 34 </head> | |
| 35 <body> | |
| 36 <header> | |
| 37 <h1>{title}</h1> | |
| 38 </header> | |
| 39 <hr> | |
| 40 <div class="content"> | |
| 41 <nav> | |
| 42 <ul>{items# | |
| 43 <li><a href="{item.url}" title="{item.module}">{item.name}</a></li>} | |
| 44 </ul> | |
| 45 </nav> | |
| 46 </div> | |
| 47 <hr> | |
| 48 <footer> | |
| 49 <br> | |
| 50 <div class="powered-by">Prosody {prosody_version?}</div> | |
| 51 </footer> | |
| 52 </body> | |
| 53 </html> | |
| 54 ]]; | |
| 55 | 13 |
| 56 local canonical = module:http_url(nil, "/"); | 14 local canonical = module:http_url(nil, "/"); |
| 57 | 15 |
| 58 local function relative(base, link) | 16 local function relative(base, link) |
| 59 base = url.parse(base); | 17 base = url.parse(base); |
