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.5KB

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