123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="apple-mobile-web-app-capable" content="yes" />
- <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
- <meta name="theme-color" content="#ff9224">
- <link rel="stylesheet" href="../script/tocas/tocas.css">
- <script src="../script/tocas/tocas.js"></script>
- <script src="../script/jquery.min.js"></script>
- <script src="../script/ao_module.js"></script>
- <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
- <title>Blog</title>
- <style>
- body{
- background-color: white;
- }
- .postControls{
- position: absolute;
- top: 0.5em;
- right: 0.5em;
- }
- .blog.main{
- background-color: #ff9224;
- border: 1px solid #ff9224;
- color: white;
- }
- .blog.main:hover{
- background-color: #c7721c !important;
- border: 1px solid #c7721c !important;
- color: white !important;
- }
- .blog.green{
- background-color: #47d191;
- border: 1px solid #47d191;
- color: white;
- }
- .blog.green:hover{
- background-color: #38a170 !important;
- border: 1px solid #38a170 !important;
- color: white !important;
- }
- .blog.red{
- background-color: #ff3d3d;
- border: 1px solid #ff3d3d;
- color: white;
- }
- .blog.red:hover{
- background-color: #962d2d !important;
- border: 1px solid #962d2d !important;
- color: white !important;
- }
- .blog.red{
- background-color: #c4413d;
- border: 1px solid #c4413d;
- color: white;
- }
- .blog.red:hover{
- background-color: #8c302d !important;
- border: 1px solid #8c302d !important;
- color: white !important;
- }
-
- .topPad{
- margin-top: 4px;
- }
- </style>
- </head>
- <body>
- <br><br>
- <div class="ts container">
- <div>
- <h4><img class="ts mini spaced image" src="img/module_icon.png" style="margin-right: 12px;"> Blog Writer</h4>
- </div>
- <div class="ts divider"></div>
- <div class="ts stackable grid">
- <!-- Post container-->
- <div class="twelve wide column" id="postList">
-
- </div>
- <!-- Setting container-->
- <div class="four wide column">
- <div class="ts segment">
- <a class="ts fluid small button blog main" href="editor.html"><i class="add icon"></i> New Post</a>
- <button class="ts fluid small button blog green topPad"><i class="text file outline icon"></i> Browse Blog</button>
- <div class="ts divider"></div>
- <button class="ts fluid small button"><i class="folder open icon"></i> Open Folder</button>
- <button class="ts fluid small button topPad"><i class="setting icon"></i> Settings</button>
- </div>
- </div>
- </div>
- <br><br><br>
- </div>
- <script>
- //List all the post stored in the system
- listPost();
- function openPost(object){
- //Parse the file object following ArozOS file descriptor protocol
- var filepath = $(object).attr("filepath");
- var filename = filepath.split("/").pop();
- var file = [{
- filename: filename,
- filepath: filepath
- }]
- var fd = encodeURIComponent(JSON.stringify(file));
- window.location.href = "editor.html#" + fd;
- }
- function listPost(){
- ao_module_agirun("Blog/backend/listPosts.js", {}, function(data){
- if (data.length == 0){
- //There is no post in the system
- $("#postList").html(`<div class="ts segment post">
- <h5 class="ts header">
- <div class="content">
- No Blog Posts
- <div class="sub header">Create your first post with the "New Post"</div>
- </div>
- </h5>
-
- </div>`);
- }else{
- //Render the post
- console.log(data);
- data.forEach(post => {
- //Generate the tag HTML
- var tags = post.tags;
- var tagHTML = [];
- tags.forEach(tag => {
- tagHTML.push(`<a class="section">${tag}</a>`);
- });
- tagHTML = tagHTML.join(`<div class="divider">,</div>`);
- //Post view permission indicator
- var postViewIcon = "";
- //Publish or hide post button
- var publicPostOnly = "";
- var privatePostOnly = "";
- if (post.view == "private"){
- postViewIcon = `<i class="hide icon"></i> Draft`;
- publicPostOnly = "display:none;"
- }else{
- postViewIcon = `<i class="unhide icon"></i> Published`;
- privatePostOnly = "display:none;"
- }
- $("#postList").append(`<div class="ts segment post">
- <div class="ts header">
- <a href="#" onclick="openPost(this);" filepath="${post.filepath}">${post.title} </a>
- <div class="sub header">
- <div>
- <span style="padding-right: 1em;">${postViewIcon}</span>
- <span style="padding-right: 1em;"><i class="calendar icon"></i> ${post.modtime}</span>
- <div class="ts breadcrumb">
- <div class="section">
- <i class="tag icon"></i>
- </div>
- ${tagHTML}
- </div>
- </div>
- </div>
- </div>
- ${stripHtml(post.content)}
-
- <div class="postControls">
- <button style="${publicPostOnly}" class="ts mini icon button blog red" title="Hide Post"><i class="hide icon"></i></button>
- <button style="${privatePostOnly}" class="ts mini icon button blog green" title="Publish Post"><i class="upload icon"></i></button>
- </div>
- </div>`)
- })
- }
- });
- function stripHtml(html){
- let tmp = document.createElement("DIV");
- tmp.innerHTML = html;
- var result = tmp.textContent || tmp.innerText || "";
- return result;
- }
- }
- </script>
- </body>
- </html>
|