Publish HTML quickly. https://html.house
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

176 lines
5.7 KiB

  1. {{define "editor"}}<!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>CSShorse</title>
  5. <link rel="stylesheet" type="text/css" href="/css/house.css" />
  6. <link rel="shortcut icon" href="/favicon.ico" />
  7. <link rel="icon" type="image/png" href="/img/favicon-chrome.png" sizes="192x192">
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  9. <meta name="theme-color" content="#888888" />
  10. <meta name="description" content="Publish HTML with CSShorse.">
  11. <meta name="application-name" content="CSShorse">
  12. <meta name="application-url" content="https://html.house">
  13. <meta itemprop="name" content="CSShorse">
  14. <meta itemprop="description" content="Publish HTML with CSShorse.">
  15. <meta name="twitter:card" content="summary_large_image">
  16. <meta name="twitter:site" content="@HTMLhouse">
  17. <meta name="twitter:title" content="HTMLhouse">
  18. <meta name="twitter:description" content="Publish HTML with CSShorse.">
  19. <meta property="og:title" content="CSShorse" />
  20. <meta property="og:site_name" content="CSShorse" />
  21. <meta property="og:type" content="object" />
  22. <meta property="og:url" content="https://html.house/" />
  23. <meta property="og:description" content="Publish HTML with CSShorse." />
  24. </head>
  25. <body>
  26. <header>
  27. <h1>CSShorse</h1>
  28. <nav>
  29. {{if .ID}}<a class="home" href="/">&lt;&#128052;/&gt;</a>{{end}}
  30. <a href="/about.html">about</a>
  31. <a href="/contact.html">contact</a>
  32. </nav>
  33. {{if .ID}}<a href="{{.SiteURL}}" target="site">view</a>{{end}}
  34. {{if .AllowPublish}}
  35. <a id="publish" href="#">{{if .ID}}update{{else}}publish{{end}}</a>
  36. <input type="checkbox" name="public" id="public"{{if .Public}} checked="checked"{{end}} /><label for="public">public</label>
  37. {{end}}
  38. </header>
  39. <pre id="css-editor" class="editor"></pre>
  40. <div id="preview-wrap">
  41. <iframe id="preview"></iframe>
  42. </div>
  43. <script src="/js/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
  44. <script src="/js/ace.js" type="text/javascript" charset="utf-8"></script>
  45. <script src="/js/h.js"></script>
  46. <script>
  47. let style;
  48. (function() {
  49. var publishing = false;
  50. var $publishBtn = $("#publish");
  51. var $publicCheck = document.getElementById("public");
  52. {{if .ID}}{{else}}var orig = "{{.Content}}";
  53. $publishBtn.addClass("no");{{end}}
  54. var houses = JSON.parse(H.get('neighborhood', '[]'));
  55. var hasBuilt = houses.length > 0;
  56. function updatePreview() {
  57. var val = editor.getSession().getValue();
  58. try {
  59. $view.contents().find("head").find("style").html(val);
  60. } catch (err) {
  61. console.error(err);
  62. }
  63. {{if .ID}}{{else}}if (val != orig) {
  64. publishing = false;
  65. $publishBtn.removeClass("no");
  66. $publishBtn.text("publish");
  67. } else {
  68. publishing = true;
  69. $publishBtn.addClass("no");
  70. $publishBtn.text("publish" + (!hasBuilt ? " (edit first)" : ""));
  71. }{{end}}
  72. }
  73. var justPublished = false;
  74. var editor = ace.edit("css-editor");
  75. var $view = $('#preview');
  76. editor.setTheme("ace/theme/chrome");
  77. editor.session.setMode("ace/mode/css");
  78. editor.getSession().on('change', updatePreview);
  79. {{if .ID}}{{else}}var saved = H.get('constructionSite', '');
  80. if (saved !== '') {
  81. //editor.setValue(saved);
  82. }{{end}}
  83. // Populate initial page
  84. var iframe = document.getElementById('preview');
  85. iframe = iframe.contentWindow || ( iframe.contentDocument.document || iframe.contentDocument);
  86. iframe.document.open();
  87. iframe.document.write('{{.Content}}');
  88. iframe.document.close();
  89. $view.on("load", function() {
  90. style = $view.contents().find("head").find("style").get(0)
  91. if (typeof style !== "undefined") {
  92. editor.setValue(style.innerHTML)
  93. } else {
  94. $view.contents().find("head").append('<style type="text/css"></style>');
  95. }
  96. });
  97. {{if .ID}}{{else}}window.addEventListener('beforeunload', function(e) {
  98. if (!justPublished) {
  99. H.set('constructionSite', editor.getSession().getValue());
  100. }
  101. return null;
  102. });{{end}}
  103. if (hasBuilt) {
  104. $('header').append('<a href="/houses.html">my pages</a>');
  105. }
  106. {{if .ID}}var token;
  107. for (var i=0; i<houses.length; i++) {
  108. if (houses[i].id == "{{.ID}}") {
  109. token = houses[i].token;
  110. break;
  111. }
  112. }
  113. if (typeof token === "undefined") {
  114. $publishBtn.addClass("no");
  115. }{{else}}
  116. {{end}}
  117. $publishBtn.on('click', function(e) {
  118. e.preventDefault();
  119. if (publishing) {
  120. return;
  121. }
  122. publishing = true;
  123. $.ajax({
  124. type: "POST",
  125. url: "/⌂/{{if .ID}}{{.ID}}{{else}}create{{end}}",{{if .ID}}
  126. beforeSend: function (request) {
  127. request.setRequestHeader("Authorization", token);
  128. },{{end}}
  129. data: {html: editor.getSession().getValue(), public: $publicCheck.checked ? "true" : ""},
  130. success: function(data, status, xhr) {
  131. publishing = false;
  132. {{if .ID}}if (data.code == 200) { {{else}}if (data.code == 201) {
  133. var houses = JSON.parse(H.get('neighborhood', '[]'));
  134. houses.push({id: data.data.id, token: xhr.getResponseHeader('Authorization')});
  135. H.set('neighborhood', JSON.stringify(houses));{{end}}
  136. justPublished = true;
  137. {{if .ID}}{{else}}H.remove('constructionSite');{{end}}
  138. window.location = '/' + data.data.id + '.html';
  139. } else {
  140. alert(data.error_msg);
  141. }
  142. },
  143. error: function(jqXHR, status, error) {
  144. publishing = false;
  145. alert(error);
  146. }
  147. });
  148. });
  149. var _paq = _paq || [];
  150. _paq.push(['trackPageView']);
  151. _paq.push(['enableLinkTracking']);
  152. (function() {
  153. var u="//analytics.write.as/";
  154. _paq.push(['setTrackerUrl', u+'piwik.php']);
  155. _paq.push(['setSiteId', 34]);
  156. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  157. g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  158. })();
  159. })();
  160. </script>
  161. <noscript><p><img src="//analytics.write.as/piwik.php?idsite=34" style="border:0;" alt="" /></p></noscript>
  162. </body>
  163. </html>{{end}}