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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. padding: 4px;
  37. white-space: nowrap;
  38. }
  39. body.dark pre, body.dark code {
  40. background: #333333;
  41. }
  42. td {
  43. padding: .5em;
  44. }
  45. #settings, #container {
  46. box-sizing: border-box;
  47. margin: auto;
  48. max-width: 700px;
  49. padding: 0 1em;
  50. width: 100%;
  51. }
  52. #settings {
  53. display: flex;
  54. padding: 1em;
  55. }
  56. #sun, #letter {
  57. cursor: pointer;
  58. }
  59. #sun:hover, #letter:hover {
  60. transform: scale(1.1);
  61. }
  62. #sun {
  63. margin-right: 1em;
  64. }
  65. #container {
  66. line-height: 1.5;
  67. }
  68. h2 {
  69. border-bottom: 1px solid #dddddd;
  70. padding-bottom: .3em;
  71. }
  72. `;
  73. export default (title: string, content: string, stylesheet: string = defaultStylesheet) => `
  74. <html>
  75. <head>
  76. <title>Markarth - ${title}</title>
  77. <meta name="viewport" content="width=device-width">
  78. <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">
  79. <style>
  80. ${stylesheet}
  81. </style>
  82. </head>
  83. <body>
  84. <div id="settings">
  85. ${sun} ${letter}
  86. </div>
  87. <div id="container">
  88. ${content}
  89. </div>
  90. <script>
  91. window.onload = () => {
  92. const ws = new WebSocket('ws://localhost:40510');
  93. ws.onmessage = ({ data }) => {
  94. console.log('Changes detected, reloading');
  95. document.querySelector('#container').innerHTML = data;
  96. }
  97. document.querySelector('#sun').addEventListener('click', (e) => {
  98. document.body.classList.toggle('dark');
  99. });
  100. document.querySelector('#letter').addEventListener('click', (e) => {
  101. document.body.classList.toggle('serif');
  102. });
  103. }
  104. </script>
  105. </body>
  106. </html>
  107. `;