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.
 
 
 
 

149 lines
4.7 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:title" content="HTMLhouse">
  17. <meta name="twitter:description" content="Publish HTML with HTMLhouse.">
  18. <meta property="og:title" content="HTMLhouse" />
  19. <meta property="og:site_name" content="HTMLhouse" />
  20. <meta property="og:type" content="object" />
  21. <meta property="og:url" content="https://html.house/" />
  22. <meta property="og:description" content="Publish HTML with HTMLhouse." />
  23. </head>
  24. <body>
  25. <header>
  26. <h1>HTMLhouse</h1>
  27. <nav>
  28. {{if .ID}}<a class="home" href="/">&lt;&#8962;/&gt;</a>{{end}}
  29. <a href="/browse">browse</a>
  30. <a href="/about.html">about</a>
  31. <a href="/contact.html">contact</a>
  32. </nav>
  33. {{if .ID}}<a href="/{{.ID}}.html">view</a>{{end}}
  34. <a id="publish" href="#">{{if .ID}}update{{else}}publish{{end}}</a>
  35. </header>
  36. <pre id="editor">{{.Content}}</pre>
  37. <div id="preview-wrap">
  38. <iframe id="preview"></iframe>
  39. </div>
  40. <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
  41. <script src="/js/ace.js" type="text/javascript" charset="utf-8"></script>
  42. <script src="https://write.as/js/h.js"></script>
  43. <script>
  44. var publishing = false;
  45. var $publishBtn = $("#publish");
  46. {{if .ID}}{{else}}var orig = "{{.Content}}";
  47. $publishBtn.addClass("no");{{end}}
  48. var houses = JSON.parse(H.get('neighborhood', '[]'));
  49. var hasBuilt = houses.length > 0;
  50. function updatePreview() {
  51. var val = editor.getSession().getValue();
  52. $view.contents().find('body').html(val);
  53. {{if .ID}}{{else}}if (val != orig) {
  54. publishing = false;
  55. $publishBtn.removeClass("no");
  56. $publishBtn.text("publish");
  57. } else {
  58. publishing = true;
  59. $publishBtn.addClass("no");
  60. $publishBtn.text("publish" + (!hasBuilt ? " (edit first)" : ""));
  61. }{{end}}
  62. }
  63. var justPublished = false;
  64. var editor = ace.edit("editor");
  65. var $view = $('#preview');
  66. editor.setTheme("ace/theme/chrome");
  67. editor.session.setMode("ace/mode/html");
  68. editor.getSession().on('change', updatePreview);
  69. {{if .ID}}{{else}}var saved = H.get('constructionSite', '');
  70. if (saved !== '') {
  71. editor.setValue(saved);
  72. }{{end}}
  73. updatePreview();
  74. {{if .ID}}{{else}}window.addEventListener('beforeunload', function(e) {
  75. if (!justPublished) {
  76. H.set('constructionSite', editor.getSession().getValue());
  77. }
  78. return null;
  79. });{{end}}
  80. if (hasBuilt) {
  81. $('header').append('<a href="/houses.html">my pages</a>');
  82. }
  83. {{if .ID}}var token;
  84. for (var i=0; i<houses.length; i++) {
  85. if (houses[i].id == "{{.ID}}") {
  86. token = houses[i].token;
  87. break;
  88. }
  89. }
  90. if (typeof token === "undefined") {
  91. $publishBtn.addClass("no");
  92. }{{else}}
  93. {{end}}
  94. $publishBtn.on('click', function(e) {
  95. e.preventDefault();
  96. if (publishing) {
  97. return;
  98. }
  99. publishing = true;
  100. $.ajax({
  101. type: "POST",
  102. url: "/⌂/{{if .ID}}{{.ID}}{{else}}create{{end}}",{{if .ID}}
  103. beforeSend: function (request) {
  104. request.setRequestHeader("Authorization", token);
  105. },{{end}}
  106. data: {html: editor.getSession().getValue()},
  107. success: function(data, status, xhr) {
  108. publishing = false;
  109. {{if .ID}}if (data.meta.code == 200) { {{else}}if (data.meta.code == 201) {
  110. var houses = JSON.parse(H.get('neighborhood', '[]'));
  111. houses.push({id: data.data.id, token: xhr.getResponseHeader('Authorization')});
  112. H.set('neighborhood', JSON.stringify(houses));{{end}}
  113. justPublished = true;
  114. {{if .ID}}{{else}}H.remove('constructionSite');{{end}}
  115. window.location = '/' + data.data.id + '.html';
  116. } else {
  117. alert(data.meta.error_msg);
  118. }
  119. },
  120. error: function(jqXHR, status, error) {
  121. publishing = false;
  122. alert(error);
  123. }
  124. });
  125. });
  126. </script>
  127. <script type="text/javascript">
  128. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  129. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  130. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  131. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  132. ga('create', 'UA-47877053-8', 'auto');
  133. ga('send', 'pageview');
  134. </script>
  135. </body>
  136. </html>{{end}}