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.
 
 
 
 

162 lines
5.2 KiB

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