Preview local Markdown files live in a web browser
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.

template.ts 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import letter from './assets/letter';
  2. import sun from './assets/sun';
  3. const defaultStylesheet = `
  4. * {
  5. box-sizing: border-box;
  6. margin-top: 0;
  7. }
  8. body {
  9. background: #eaeaea;
  10. color: #121212;
  11. font-family: Helvetica Neue, sans-serif;
  12. font-size: 16px;
  13. margin: 0;
  14. }
  15. body.dark {
  16. background: #121212;
  17. color: #eaeaea;
  18. }
  19. body.serif {
  20. font-family: Garamond, serif;
  21. }
  22. a {
  23. color: #0366d6;
  24. text-decoration: none;
  25. }
  26. a:hover {
  27. text-decoration: underline;
  28. }
  29. body.dark a {
  30. color: #46a9ff;
  31. }
  32. pre, code {
  33. border-radius: 4px;
  34. font-family: Source Code Pro;
  35. font-size: 16px;
  36. overflow-x: scroll;
  37. }
  38. p code {
  39. white-space: nowrap;
  40. }
  41. pre code {
  42. display: block;
  43. overflow-x: scroll;
  44. white-space: pre;
  45. width: 100%;
  46. }
  47. body.dark pre, body.dark code {
  48. background: #333333;
  49. }
  50. td {
  51. padding: .5em;
  52. }
  53. #settings, #container {
  54. box-sizing: border-box;
  55. margin: auto;
  56. max-width: 90ch;
  57. padding: 0 1em;
  58. width: 100%;
  59. }
  60. #settings {
  61. display: flex;
  62. padding: 1em;
  63. }
  64. #sun, #letter {
  65. cursor: pointer;
  66. }
  67. #sun:hover, #letter:hover {
  68. transform: scale(1.1);
  69. }
  70. #sun {
  71. margin-right: 1em;
  72. }
  73. #container {
  74. line-height: 1.5;
  75. }
  76. h2 {
  77. border-bottom: 1px solid #dddddd;
  78. padding-bottom: .3em;
  79. }
  80. `;
  81. export default (
  82. title: string,
  83. content: string,
  84. theme: string,
  85. stylesheet: string = defaultStylesheet,
  86. ) => `
  87. <html>
  88. <head>
  89. <title>Markarth - ${title}</title>
  90. <meta name="viewport" content="width=device-width">
  91. <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">
  92. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/${theme}.min.css">
  93. <style>
  94. ${stylesheet}
  95. </style>
  96. </head>
  97. <body>
  98. <div id="settings">
  99. ${sun} ${letter}
  100. </div>
  101. <div id="container">
  102. ${content}
  103. </div>
  104. <script>
  105. window.onload = () => {
  106. const ws = new WebSocket('ws://localhost:40510');
  107. ws.onmessage = ({ data }) => {
  108. console.log('Changes detected, reloading');
  109. document.querySelector('#container').innerHTML = data;
  110. }
  111. document.querySelector('#sun').addEventListener('click', (e) => {
  112. document.body.classList.toggle('dark');
  113. });
  114. document.querySelector('#letter').addEventListener('click', (e) => {
  115. document.body.classList.toggle('serif');
  116. });
  117. document.querySelectorAll('pre code').forEach(codeBlock => {
  118. codeBlock.classList.add('hljs');
  119. });
  120. }
  121. </script>
  122. </body>
  123. </html>
  124. `;