Publish HTML quickly. https://html.house
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

158 linhas
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="https://code.jquery.com/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. $view.contents().find('body').html(val);
  57. {{if .ID}}{{else}}if (val != orig) {
  58. publishing = false;
  59. $publishBtn.removeClass("no");
  60. $publishBtn.text("publish");
  61. } else {
  62. publishing = true;
  63. $publishBtn.addClass("no");
  64. $publishBtn.text("publish" + (!hasBuilt ? " (edit first)" : ""));
  65. }{{end}}
  66. }
  67. var justPublished = false;
  68. var editor = ace.edit("editor");
  69. var $view = $('#preview');
  70. editor.setTheme("ace/theme/chrome");
  71. editor.session.setMode("ace/mode/html");
  72. editor.getSession().on('change', updatePreview);
  73. {{if .ID}}{{else}}var saved = H.get('constructionSite', '');
  74. if (saved !== '') {
  75. editor.setValue(saved);
  76. }{{end}}
  77. updatePreview();
  78. {{if .ID}}{{else}}window.addEventListener('beforeunload', function(e) {
  79. if (!justPublished) {
  80. H.set('constructionSite', editor.getSession().getValue());
  81. }
  82. return null;
  83. });{{end}}
  84. if (hasBuilt) {
  85. $('header').append('<a href="/houses.html">my pages</a>');
  86. }
  87. {{if .ID}}var token;
  88. for (var i=0; i<houses.length; i++) {
  89. if (houses[i].id == "{{.ID}}") {
  90. token = houses[i].token;
  91. break;
  92. }
  93. }
  94. if (typeof token === "undefined") {
  95. $publishBtn.addClass("no");
  96. }{{else}}
  97. {{end}}
  98. $publishBtn.on('click', function(e) {
  99. e.preventDefault();
  100. if (publishing) {
  101. return;
  102. }
  103. publishing = true;
  104. $.ajax({
  105. type: "POST",
  106. url: "/⌂/{{if .ID}}{{.ID}}{{else}}create{{end}}",{{if .ID}}
  107. beforeSend: function (request) {
  108. request.setRequestHeader("Authorization", token);
  109. },{{end}}
  110. data: {html: editor.getSession().getValue(), public: $publicCheck.checked ? "true" : ""},
  111. success: function(data, status, xhr) {
  112. publishing = false;
  113. {{if .ID}}if (data.meta.code == 200) { {{else}}if (data.meta.code == 201) {
  114. var houses = JSON.parse(H.get('neighborhood', '[]'));
  115. houses.push({id: data.data.id, token: xhr.getResponseHeader('Authorization')});
  116. H.set('neighborhood', JSON.stringify(houses));{{end}}
  117. justPublished = true;
  118. {{if .ID}}{{else}}H.remove('constructionSite');{{end}}
  119. window.location = '/' + data.data.id + '.html';
  120. } else {
  121. alert(data.meta.error_msg);
  122. }
  123. },
  124. error: function(jqXHR, status, error) {
  125. publishing = false;
  126. alert(error);
  127. }
  128. });
  129. });
  130. var _paq = _paq || [];
  131. _paq.push(["setCookieDomain", "*.html.house"]);
  132. _paq.push(["setDomains", ["*.html.house"]]);
  133. _paq.push(['trackPageView']);
  134. _paq.push(['enableLinkTracking']);
  135. (function() {
  136. var u="//analytics.write.as/";
  137. _paq.push(['setTrackerUrl', u+'piwik.php']);
  138. _paq.push(['setSiteId', 3]);
  139. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  140. g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  141. })();
  142. })();
  143. </script>
  144. <noscript><p><img src="//analytics.write.as/piwik.php?idsite=3" style="border:0;" alt="" /></p></noscript>
  145. </body>
  146. </html>{{end}}