bookish-press 0.5.23 → 0.5.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,8 @@ $: {
29
29
  // Set the theme, whatever it is, and change it when the edition changes
30
30
  setTheme(edition.getTheme() ?? BookishTheme);
31
31
  }
32
+ // The CSS to set on the edition.
33
+ let themeCSS;
32
34
  // Set the theme on mount.
33
35
  onMount(() => {
34
36
  setTheme(edition.getTheme() ?? BookishTheme);
@@ -36,74 +38,25 @@ onMount(() => {
36
38
  // Redirect old hash routes by simply replacing their hash before routing.
37
39
  if (typeof window !== 'undefined' && window.location.hash.startsWith('#/'))
38
40
  goto(location.hash.replace('#', ''));
39
- /** Given a theme, sets the appropriate CSS rules in the browser to apply the theme.*/
41
+ /** Given a theme, sets the appropriate CSS rules in the browser to apply the theme. */
40
42
  function setTheme(theme) {
41
- // Allow for prerendering; rely on mount callback to set the theme.
42
- if (typeof document === 'undefined')
43
- return;
44
- // If the theme is being unset, make sure we've removed any overrding style declaration.
45
- // This let's the default theme kick in.
46
- let themeTagImports = document.getElementById('bookish-theme-imports');
47
- let themeTagCSS = document.getElementById('bookish-theme');
48
- // We only want to set it if it's actually different than what's currently set.
49
- // Otherwise during editing we get lots of jittery changes on each edit, because the
50
- // whole edition is rerendering. To check this, we set a data attribute on the style tag containing
51
- // a stringify of the theme set. We do this separately for the imports, since they can have more
52
- // major changes than the spacing and color sizes, changing fonts especially.
53
- const themeTagCSSValue = themeTagCSS?.dataset.css;
54
- const themeTagImportsValue = themeTagImports?.dataset.imports;
55
- const newThemeTagCSSValue = JSON.stringify(theme);
56
- const newThemeTagImportsValue = JSON.stringify(theme?.imports);
57
- if (theme !== null) {
58
- // If the imports changed, update theme.
59
- if (themeTagImportsValue !== newThemeTagImportsValue) {
60
- // If it's being set, create a new style tag.
61
- const newThemeImportsTag = document.createElement('style');
62
- // Give it an ID so we can remove it later.
63
- newThemeImportsTag.setAttribute('id', 'bookish-theme-imports');
64
- newThemeImportsTag.dataset.imports = newThemeTagImportsValue;
65
- // Insert any import statements, then any rules.
66
- const css = `${(theme.imports ?? [])
67
- .map((url) => `@import url(${url});`)
68
- .join('\n')}`;
69
- newThemeImportsTag.appendChild(document.createTextNode(css));
70
- document.head.appendChild(newThemeImportsTag);
71
- // Remove the old tag
72
- themeTagImports?.remove();
73
- }
74
- // If the rules changed, update them.
75
- if (themeTagCSSValue !== newThemeTagCSSValue) {
76
- // If it's being set, create a new style tag.
77
- const newThemeCSSTag = document.createElement('style');
78
- // Give it an ID so we can remove it later.
79
- newThemeCSSTag.setAttribute('id', 'bookish-theme');
80
- newThemeCSSTag.dataset.css = newThemeTagCSSValue;
81
- // Insert any import statements, then any rules.
82
- const css = `
83
- ${(theme.imports ?? [])
84
- .map((url) => `@import url(${url});`)
85
- .join('\n')}
86
- .bookish {
87
- ${theme.light ? toRules(theme.light) : ''}
88
- ${theme.fonts ? toRules(theme.fonts) : ''}
89
- ${theme.sizes ? toRules(theme.sizes) : ''}
90
- ${theme.weights ? toRules(theme.weights) : ''}
91
- ${theme.spacing ? toRules(theme.spacing) : ''}
92
- }
93
- .dark {
94
- ${theme.dark ? toRules(theme.dark) : ''}
95
- }`;
96
- newThemeCSSTag.appendChild(document.createTextNode(css));
97
- document.head.appendChild(newThemeCSSTag);
98
- // Remove the old tag
99
- themeTagCSS?.remove();
100
- }
101
- }
102
- else {
103
- // Remove the old tags, unsetting the theme.
104
- themeTagImports?.remove();
105
- themeTagCSS?.remove();
106
- }
43
+ if (theme === null)
44
+ theme = BookishTheme;
45
+ themeCSS = `
46
+ ${(theme.imports ?? [])
47
+ .map((url) => `@import url(${url});`)
48
+ .join('\n')}
49
+ .bookish {
50
+ ${theme.light ? toRules(theme.light) : ''}
51
+ ${theme.fonts ? toRules(theme.fonts) : ''}
52
+ ${theme.sizes ? toRules(theme.sizes) : ''}
53
+ ${theme.weights ? toRules(theme.weights) : ''}
54
+ ${theme.spacing ? toRules(theme.spacing) : ''}
55
+ }
56
+ .dark {
57
+ ${theme.dark ? toRules(theme.dark) : ''}
58
+ }
59
+ `;
107
60
  }
108
61
  function toRules(set) {
109
62
  return Object.keys(set)
@@ -124,6 +77,19 @@ function toRules(set) {
124
77
  }
125
78
  </script>
126
79
 
80
+ <!-- Keep the imports up to date -->
81
+ <svelte:head>
82
+ {@html '<' + `style>${themeCSS}</style>`}
83
+
84
+ <meta property="og:title" content={edition.getTitle()} />
85
+ <meta property="og:image" content={edition.getImage('cover')} />
86
+ <meta property="og:description" content={edition.getDescription()} />
87
+ <!-- <meta
88
+ property="og:url"
89
+ content="https://criticallyconsciouscomputing.org"
90
+ /> -->
91
+ </svelte:head>
92
+
127
93
  <main class="bookish {$darkMode ? ' dark' : ''}">
128
94
  <slot />
129
95
  </main>
@@ -1,11 +1,8 @@
1
1
  <script>import { onMount } from 'svelte';
2
- import { building } from '$app/environment';
3
2
  import Loading from './Loading.svelte';
4
3
  export let title;
5
4
  export let afterLoaded = undefined;
6
- // If we're building, we're loaded. This ensures that prerendering doesn't get blocked.
7
- // See: https://kit.svelte.dev/docs/modules
8
- let loaded = building;
5
+ let loaded = false;
9
6
  let lastHeight = 0;
10
7
  let intervalID = null;
11
8
  let mountTime = Date.now();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bookish-press",
3
3
  "private": false,
4
- "version": "0.5.23",
4
+ "version": "0.5.25",
5
5
  "type": "module",
6
6
  "description": "A platform for reading and writing readable, accessible, beautiful online books.",
7
7
  "license": "MIT",