some updates
This commit is contained in:
parent
9773f5908b
commit
5dc65eb143
|
@ -75,7 +75,11 @@ module.exports = function(grunt) {
|
||||||
'node_modules/jquery-pjax/jquery.pjax.js',
|
'node_modules/jquery-pjax/jquery.pjax.js',
|
||||||
'node_modules/jquery-serializejson/jquery.serializejson.min.js',
|
'node_modules/jquery-serializejson/jquery.serializejson.min.js',
|
||||||
'node_modules/codemirror/lib/codemirror.js',
|
'node_modules/codemirror/lib/codemirror.js',
|
||||||
'node_modules/codemirror/mode/markdown/markdown.js'
|
'node_modules/codemirror/mode/css/css.js',
|
||||||
|
'node_modules/codemirror/mode/javascript/javascript.js',
|
||||||
|
'node_modules/codemirror/mode/markdown/markdown.js',
|
||||||
|
'node_modules/codemirror/mode/sass/sass.js',
|
||||||
|
'node_modules/codemirror/mode/htmlmixed/htmlmixed.js'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
$(document).ready(function(){$(document).pjax("a","#main")}),$(document).on("ready pjax:success",function(){$(".scroll").perfectScrollbar(),$("#logout").click(function(a){return a.preventDefault(),$.ajax({type:"GET",url:"/admin",async:!1,username:"username",password:"password",headers:{Authorization:"Basic xxx"}}).fail(function(){window.location="/"}),!1}),$(".editor")[0]&&(editor=!1,preview=$("#preview-area"),textarea=$("#content-area"),textarea[0]&&(options={mode:"markdown",theme:"mdn-like",lineWrapping:!0,lineNumbers:!0,scrollbarStyle:null},"markdown"==textarea.data("extension")&&(options.lineNumbers=!1),editor=CodeMirror.fromTextArea(textarea[0],options)),codemirror=$(".CodeMirror"),$("#preview").click(function(a){if(a.preventDefault(),"true"==$(this).data("previewing"))preview.hide(),codemirror.fadeIn(),$(this).data("previewing","false"),notification({text:"Think, relax and do the better you can!",type:"information",timeout:2e3});else{editor.save();var b=new showdown.Converter,c=textarea.val(),d=b.makeHtml(c);codemirror.hide(),preview.html(d).fadeIn(),$(this).data("previewing","true"),notification({text:"This is how your post looks like.",type:"information",timeout:2e3})}return!1}),$("form").submit(function(a){a.preventDefault();var b=JSON.stringify($(this).serializeJSON()),c=$(this).find("input[type=submit]:focus");console.log(b),$.ajax({type:"POST",url:window.location,data:b,headers:{"X-Regenerate":c.data("regenerate"),"X-Content-Type":c.data("type")},dataType:"json",encode:!0}).done(function(a){notification({text:c.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)})}),$(".add").click(function(a){return a.preventDefault(),fieldset=$(this).closest("fieldset"),fieldset.append('<input name="'+fieldset.attr("name")+'" id="'+fieldset.attr("name")+'" value=""></input><br>'),!1}))}),$(document).on("pjax:send",function(){$("#loading").fadeIn()}),$(document).on("pjax:complete",function(){$("#loading").fadeOut()}),$.noty.themes.admin={name:"admin",helpers:{},modal:{css:{position:"fixed",width:"100%",height:"100%",backgroundColor:"#000",zIndex:1e4,opacity:.6,display:"none",left:0,top:0}}},$.noty.defaults={layout:"topRight",theme:"admin",dismissQueue:!0,animation:{open:"animated bounceInRight",close:"animated fadeOut",easing:"swing",speed:500},timeout:!1,force:!1,modal:!1,maxVisible:5,killer:!1,closeWith:["click"],callback:{onShow:function(){},afterShow:function(){},onClose:function(){},afterClose:function(){},onCloseClick:function(){}},buttons:!1},notification=function(a){var b;switch(a.type){case"success":b='<i class="fa fa-check"></i>';break;case"error":b='<i class="fa fa-times"></i>';break;case"warning":b='<i class="fa fa-exclamation"></i>';break;case"information":b='<i class="fa fa-info"></i>';break;default:b='<i class="fa fa-bell"></i>'}var c={template:'<div class="noty_message"><span class="noty_icon">'+b+'</span><span class="noty_text"></span></div>'};a=$.extend({},c,a),noty(a)};
|
$(document).ready(function(){$(document).pjax("a","#main")}),$(document).on("ready pjax:success",function(){$(".scroll").perfectScrollbar(),$("#logout").click(function(a){return a.preventDefault(),$.ajax({type:"GET",url:"/admin",async:!1,username:"username",password:"password",headers:{Authorization:"Basic xxx"}}).fail(function(){window.location="/"}),!1}),$(".editor")[0]&&(editor=!1,preview=$("#preview-area"),textarea=$("#content-area"),textarea[0]&&(options={mode:textarea.data("mode"),theme:"mdn-like",lineWrapping:!0,lineNumbers:!0,scrollbarStyle:null},"markdown"==textarea.data("mode")&&(options.lineNumbers=!1),editor=CodeMirror.fromTextArea(textarea[0],options)),codemirror=$(".CodeMirror"),$("#preview").click(function(a){if(a.preventDefault(),"true"==$(this).data("previewing"))preview.hide(),codemirror.fadeIn(),$(this).data("previewing","false"),notification({text:"Think, relax and do the better you can!",type:"information",timeout:2e3});else{editor.save();var b=new showdown.Converter,c=textarea.val(),d=b.makeHtml(c);codemirror.hide(),preview.html(d).fadeIn(),$(this).data("previewing","true"),notification({text:"This is how your post looks like.",type:"information",timeout:2e3})}return!1}),$("form").submit(function(a){a.preventDefault();var b=JSON.stringify($(this).serializeJSON()),c=$(this).find("input[type=submit]:focus");console.log(b),$.ajax({type:"POST",url:window.location,data:b,headers:{"X-Regenerate":c.data("regenerate"),"X-Content-Type":c.data("type")},dataType:"json",encode:!0}).done(function(a){notification({text:c.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)})}),$(".add").click(function(a){return a.preventDefault(),fieldset=$(this).closest("fieldset"),fieldset.append('<input name="'+fieldset.attr("name")+'" id="'+fieldset.attr("name")+'" value=""></input><br>'),!1}))}),$(document).on("pjax:send",function(){$("#loading").fadeIn()}),$(document).on("pjax:complete",function(){$("#loading").fadeOut()}),$.noty.themes.admin={name:"admin",helpers:{},modal:{css:{position:"fixed",width:"100%",height:"100%",backgroundColor:"#000",zIndex:1e4,opacity:.6,display:"none",left:0,top:0}}},$.noty.defaults={layout:"topRight",theme:"admin",dismissQueue:!0,animation:{open:"animated bounceInRight",close:"animated fadeOut",easing:"swing",speed:500},timeout:!1,force:!1,modal:!1,maxVisible:5,killer:!1,closeWith:["click"],callback:{onShow:function(){},afterShow:function(){},onClose:function(){},afterClose:function(){},onCloseClick:function(){}},buttons:!1},notification=function(a){var b;switch(a.type){case"success":b='<i class="fa fa-check"></i>';break;case"error":b='<i class="fa fa-times"></i>';break;case"warning":b='<i class="fa fa-exclamation"></i>';break;case"information":b='<i class="fa fa-info"></i>';break;default:b='<i class="fa fa-bell"></i>'}var c={template:'<div class="noty_message"><span class="noty_icon">'+b+'</span><span class="noty_text"></span></div>'};a=$.extend({},c,a),noty(a)};
|
File diff suppressed because one or more lines are too long
|
@ -33,14 +33,14 @@ $(document).on('ready pjax:success', function() {
|
||||||
|
|
||||||
if (textarea[0]) {
|
if (textarea[0]) {
|
||||||
options = {
|
options = {
|
||||||
mode: 'markdown',
|
mode: textarea.data("mode"),
|
||||||
theme: 'mdn-like',
|
theme: 'mdn-like',
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
scrollbarStyle: null
|
scrollbarStyle: null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textarea.data("extension") == "markdown") {
|
if (textarea.data("mode") == "markdown") {
|
||||||
options.lineNumbers = false
|
options.lineNumbers = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
type editor struct {
|
type editor struct {
|
||||||
Name string
|
Name string
|
||||||
Class string
|
Class string
|
||||||
Extension string
|
Mode string
|
||||||
Content string
|
Content string
|
||||||
FrontMatter interface{}
|
FrontMatter interface{}
|
||||||
}
|
}
|
||||||
|
@ -174,13 +174,15 @@ func get(w http.ResponseWriter, r *http.Request, filename string) (int, error) {
|
||||||
|
|
||||||
// Create a new editor variable and set the extension
|
// Create a new editor variable and set the extension
|
||||||
page := new(editor)
|
page := new(editor)
|
||||||
page.Extension = strings.TrimPrefix(filepath.Ext(filename), ".")
|
page.Mode = strings.TrimPrefix(filepath.Ext(filename), ".")
|
||||||
page.Name = filename
|
page.Name = filename
|
||||||
|
|
||||||
|
// Sanitize the extension
|
||||||
|
page.Mode = sanitizeMode(page.Mode)
|
||||||
|
|
||||||
// Handle the content depending on the file extension
|
// Handle the content depending on the file extension
|
||||||
switch page.Extension {
|
switch page.Mode {
|
||||||
case "markdown", "md":
|
case "markdown":
|
||||||
page.Extension = "markdown"
|
|
||||||
if hasFrontMatterRune(file) {
|
if hasFrontMatterRune(file) {
|
||||||
// Starts a new buffer and parses the file using Hugo's functions
|
// Starts a new buffer and parses the file using Hugo's functions
|
||||||
buffer := bytes.NewBuffer(file)
|
buffer := bytes.NewBuffer(file)
|
||||||
|
@ -208,7 +210,7 @@ func get(w http.ResponseWriter, r *http.Request, filename string) (int, error) {
|
||||||
if hasFrontMatterRune(file) {
|
if hasFrontMatterRune(file) {
|
||||||
page.FrontMatter, err = frontmatter.Pretty(file)
|
page.FrontMatter, err = frontmatter.Pretty(file)
|
||||||
} else {
|
} else {
|
||||||
page.FrontMatter, err = frontmatter.Pretty(appendFrontMatterRune(file, page.Extension))
|
page.FrontMatter, err = frontmatter.Pretty(appendFrontMatterRune(file, page.Mode))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there were any errors
|
// Check if there were any errors
|
||||||
|
@ -256,3 +258,18 @@ func appendFrontMatterRune(frontmatter []byte, language string) []byte {
|
||||||
|
|
||||||
return frontmatter
|
return frontmatter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeMode(extension string) string {
|
||||||
|
switch extension {
|
||||||
|
case "markdown", "md":
|
||||||
|
return "markdown"
|
||||||
|
case "css", "scss":
|
||||||
|
return "css"
|
||||||
|
case "html":
|
||||||
|
return "htmlmixed"
|
||||||
|
case "js":
|
||||||
|
return "javascript"
|
||||||
|
default:
|
||||||
|
return extension
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,13 +21,13 @@
|
||||||
{{ else if eq .Class "content-only" }}
|
{{ else if eq .Class "content-only" }}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<textarea id="content-area" name="content" class="scroll" data-extension="{{ .Extension }}">{{ .Content }}</textarea>
|
<textarea id="content-area" name="content" class="scroll" data-mode="{{ .Mode }}">{{ .Content }}</textarea>
|
||||||
<div id="preview-area" class="scroll hidden"></div>
|
<div id="preview-area" class="scroll hidden"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<textarea id="content-area" name="content" class="scroll" data-extension="{{ .Extension }}">{{ .Content }}</textarea>
|
<textarea id="content-area" name="content" class="scroll" data-mode="{{ .Mode }}">{{ .Content }}</textarea>
|
||||||
<div id="preview-area" class="scroll hidden"></div>
|
<div id="preview-area" class="scroll hidden"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar scroll">
|
<div class="sidebar scroll">
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="action-bar">
|
<div class="action-bar">
|
||||||
{{ if or (eq .Extension "markdown") (eq .Extension "md") (eq .Class "full") }}
|
{{ if or (eq .Mode "markdown") (eq .Class "full") }}
|
||||||
<button id="preview" class="left">Preview</button>
|
<button id="preview" class="left">Preview</button>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<span class="left"></span>
|
<span class="left"></span>
|
||||||
|
|
Loading…
Reference in New Issue