@portosaur/core 0.6.3 → 0.8.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portosaur/core",
3
- "version": "0.6.3",
3
+ "version": "0.8.0",
4
4
  "description": "The engine of portosaur that translates YAML configuration into Docusaurus structures.",
5
5
  "license": "GPL-3.0-only",
6
6
  "author": "soymadip",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "types": "./src/index.d.ts",
29
29
  "dependencies": {
30
- "@portosaur/logger": "^0.6.3",
30
+ "@portosaur/logger": "^0.8.0",
31
31
  "favicons": "^7.2.0",
32
32
  "js-yaml": "^4.1.1",
33
33
  "rehype-katex": "7",
@@ -4,6 +4,7 @@ import { createRequire } from "module";
4
4
  import { getGitDate } from "../utils/system.mjs";
5
5
  import { porto } from "../app.mjs";
6
6
  import { resolveVars, getNestedValue } from "../utils/config.mjs";
7
+ import { getPortoDotDir } from "../utils/fs.mjs";
7
8
  import {
8
9
  resolveSiteUrl,
9
10
  resolveBasePath,
@@ -56,33 +57,38 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
56
57
  const get = (key, ...fallbacks) =>
57
58
  getNestedValue(userConfig, key, ...fallbacks);
58
59
 
59
- const siteName = get("site.title", "Your Name");
60
+ const defaultTheme =
61
+ get("theme.appearance.default_mode", "dark") === "light" ? "light" : "dark";
60
62
 
61
- // ------- Configuration Setup -------
63
+ const titleName = get("home_page.hero.title", "Your Name");
64
+ const siteName = get("site.title", titleName);
65
+ const siteFavicon = resolveAsset(
66
+ get("site.favicon", ""),
67
+ resolveAsset(get("home_page.hero.profile_pic", ""), "img/icon.png"),
68
+ );
69
+
70
+ const siteTagline = get(
71
+ "home_page.hero.desc",
72
+ "site.tagline",
73
+ "Short description about you, your passion, your goals etc.",
74
+ );
62
75
 
63
76
  // Collect static directories: local site static/, theme assets/, and portosaur dot-dir.
64
77
  const staticDirectories = [
65
78
  "static",
66
79
  assetsDir,
67
- path.join(projectDir, ".docusaurus", "portosaur"),
80
+ getPortoDotDir(projectDir),
68
81
  ].filter((dir) => dir && fs.existsSync(dir));
69
82
 
70
- const isDarkMode = get("theme.appearance.dark_mode", true);
71
- const disableSwitch = get("theme.appearance.disable_switch", false);
83
+ // ------- Configuration Setup -------
72
84
 
73
85
  return {
74
86
  projectName: siteName,
75
87
  title: siteName,
76
- tagline: get(
77
- "site.tagline",
78
- "Short description about you, your passion, your goals etc.",
79
- ),
88
+ tagline: siteTagline,
80
89
  url: siteUrl,
81
90
  baseUrl: sitePath,
82
- favicon: resolveAsset(
83
- get("site.favicon", ""),
84
- resolveAsset("favicon/favicon.ico", "img/icon.png"),
85
- ),
91
+ favicon: siteFavicon,
86
92
  organizationName: siteName,
87
93
  onBrokenAnchors: get("site.on_broken_anchors", "throw"),
88
94
  onBrokenLinks: get("site.on_broken_links", "throw"),
@@ -90,10 +96,20 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
90
96
 
91
97
  staticDirectories,
92
98
 
99
+ headTags: buildHeadTags([
100
+ ...(context.extraHeadTags || []),
101
+ ...get("site.head_tags", []),
102
+ ]),
103
+
93
104
  themeConfig: {
105
+ image: resolveAsset(get("site.social_card", "")) || undefined,
106
+ metadata: [
107
+ { name: "generator", content: `Portosaur v${porto.version}` },
108
+ { name: "theme-color", content: "var(--ifm-background-color)" },
109
+ ],
94
110
  colorMode: {
95
- defaultMode: isDarkMode ? "dark" : "light",
96
- disableSwitch,
111
+ defaultMode: defaultTheme,
112
+ disableSwitch: !get("theme.appearance.show_theme_switch", true),
97
113
  respectPrefersColorScheme: false,
98
114
  },
99
115
 
@@ -101,7 +117,7 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
101
117
  title: siteName,
102
118
  logo: {
103
119
  alt: `${siteName} logo`,
104
- src: resolveAsset(get("site.favicon", ""), "img/icon.png"),
120
+ src: siteFavicon,
105
121
  },
106
122
  hideOnScroll: get("theme.navigation.hide_navbar_on_scroll", true),
107
123
  items: [
@@ -161,14 +177,12 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
161
177
  ...(get("tasks.enable", false)
162
178
  ? [{ label: "Tasks", to: "/tasks" }]
163
179
  : []),
164
- ...(!get("theme.appearance.disable_branding", false)
180
+ ...(!get("theme.appearance.disable_project_link", false)
165
181
  ? [
166
182
  {
167
183
  label: `Portosaur v${portoVersion}`,
168
184
  className: "_nav-portosaur-version",
169
- href:
170
- porto?.homepage ||
171
- "https://github.com/soymadip/portosaur",
185
+ href: porto?.homepage ?? "#",
172
186
  },
173
187
  ]
174
188
  : []),
@@ -177,53 +191,45 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
177
191
  ],
178
192
  },
179
193
 
180
- footer: {
181
- style: "dark",
182
- copyright: get(
183
- "site.footer_text",
184
- `© ${new Date().getFullYear()} ${siteName}. Built with Portosaur.`,
185
- ),
194
+ docs: {
195
+ sidebar: {
196
+ hideable: get("theme.navigation.collapsable_sidebar", true),
197
+ },
186
198
  },
187
- },
188
199
 
189
- headTags: buildHeadTags([
190
- { meta: { name: "generator", content: `Portosaur v${porto.version}` } },
191
- { meta: { name: "theme-color", content: "var(--ifm-background-color)" } },
192
- ...(context.extraHeadTags || []),
193
- ...get("site.head_tags", []),
194
- ]),
200
+ tableOfContents: {
201
+ minHeadingLevel: 2,
202
+ maxHeadingLevel: 3,
203
+ },
204
+
205
+ markdown: {
206
+ mermaid: get("theme.markdown.mermaid", true),
207
+ emoji: get("theme.markdown.render_emoji_shortcodes", true),
208
+ on_broken_links: get("theme.markdown.on_broken_links", "throw"),
209
+ on_broken_images: get("theme.markdown.on_broken_images", "throw"),
210
+ },
211
+
212
+ ...(get("theme.footer.enable", true)
213
+ ? {
214
+ footer: {
215
+ copyright: get(
216
+ "theme.footer.message",
217
+ `© ${new Date().getFullYear()} ${titleName}.${
218
+ !get("theme.footer.disable_project_link", false)
219
+ ? ` | Built with <a href="${porto?.homepage ?? "#"}" target="_blank" rel="noopener noreferrer">Portosaur.</a>`
220
+ : ""
221
+ }`,
222
+ ),
223
+ },
224
+ }
225
+ : {}),
226
+ },
195
227
 
196
228
  // ------- Custom Fields -------
197
229
 
198
230
  customFields: {
199
231
  portoVersion,
200
232
 
201
- theme: {
202
- markdown: {
203
- mermaid: get("theme.markdown.mermaid", true),
204
- on_broken_links: get("theme.markdown.on_broken_links", "throw"),
205
- on_broken_images: get("theme.markdown.on_broken_images", "throw"),
206
- },
207
-
208
- navigation: {
209
- collapsable_sidebar: get(
210
- "theme.navigation.collapsable_sidebar",
211
- true,
212
- ),
213
-
214
- hide_navbar_on_scroll: get(
215
- "theme.navigation.hide_navbar_on_scroll",
216
- true,
217
- ),
218
- },
219
-
220
- appearance: {
221
- dark_mode: get("theme.appearance.dark_mode", true),
222
- disable_switch: get("theme.appearance.disable_switch", false),
223
- disable_branding: get("theme.appearance.disable_branding", false),
224
- },
225
- },
226
-
227
233
  heroSection: {
228
234
  profilePic: resolveAsset(
229
235
  get("home_page.hero.profile_pic", ""),
@@ -231,7 +237,7 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
231
237
  ),
232
238
 
233
239
  intro: get("home_page.hero.intro", "Hello there, I'm"),
234
- title: get("home_page.hero.title", "site.title", "Your Name"),
240
+ title: titleName,
235
241
  subtitle: get("home_page.hero.subtitle", "I am a"),
236
242
  profession: get("home_page.hero.profession", "Your Profession"),
237
243
  desc: get("home_page.hero.desc", "Welcome to my portfolio."),
@@ -301,6 +307,7 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
301
307
  docs: {
302
308
  routeBasePath: "notes",
303
309
  path: "notes",
310
+ breadcrumbs: get("theme.navigation.breadcrumbs", true),
304
311
  sidebarPath: path.resolve(
305
312
  portoPaths.theme ?? context.portoRoot ?? "",
306
313
  "config/sidebar.jsx",
@@ -313,6 +320,14 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
313
320
  showReadingTime: false,
314
321
  remarkPlugins: [remarkMath],
315
322
  rehypePlugins: [rehypeKatex],
323
+ feedOptions: {
324
+ type: get("site.rss.enable", true) ? "all" : null,
325
+ copyright: get(
326
+ "site.rss.copyright",
327
+ `Copyright © ${new Date().getFullYear()} ${siteName}.`,
328
+ ),
329
+ description: get("site.rss.desc", siteTagline),
330
+ },
316
331
  },
317
332
  theme: {
318
333
  customCss: path.resolve(
@@ -331,9 +346,10 @@ export function buildDocuConfig(rawUserConfig, projectDir, context = {}) {
331
346
  (() => {
332
347
  const require = createRequire(import.meta.url);
333
348
  return require.resolve("@easyops-cn/docusaurus-search-local", {
334
- paths: [portoPaths.theme ?? context.portoRoot ?? ""],
349
+ paths: [projectDir, portoPaths.theme ?? context.portoRoot ?? ""],
335
350
  });
336
351
  })(),
352
+
337
353
  {
338
354
  hashed: true,
339
355
  indexDocs: true,
@@ -1,5 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { getPortoDotDir } from "../utils/fs.mjs";
3
4
  import { favicons } from "favicons";
4
5
  import { downloadImage } from "../utils/imageDownloader.mjs";
5
6
  import { reshapeImage } from "../utils/imageProcessor.mjs";
@@ -121,7 +122,7 @@ export async function generateFavicons(siteDir, options = {}) {
121
122
  }
122
123
  }
123
124
 
124
- const cacheDir = path.join(siteDir, ".docusaurus", "portosaur", "cache");
125
+ const cacheDir = path.join(getPortoDotDir(siteDir), "cache");
125
126
  createDirectoryIfNotExists(cacheDir);
126
127
  const reshapedImagePath = path.join(cacheDir, "profile_pic_reshaped.png");
127
128
  const tempFiles = [];
package/src/index.mjs CHANGED
@@ -2,7 +2,7 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import yaml from "js-yaml";
4
4
 
5
- export { mirrorSync, loadPkg } from "./utils/fs.mjs";
5
+ export { mirrorSync, loadPkg, getPortoDotDir } from "./utils/fs.mjs";
6
6
 
7
7
  export {
8
8
  deepMerge,
package/src/utils/fs.mjs CHANGED
@@ -2,6 +2,15 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import { text } from "../app.mjs";
4
4
 
5
+ /**
6
+ * Gets the standardized path to the hidden Portosaur data directory.
7
+ * @param {string} siteDir - The project root directory.
8
+ * @returns {string} The resolved path.
9
+ */
10
+ export function getPortoDotDir(siteDir) {
11
+ return path.join(siteDir, ".docusaurus", ".portosaur");
12
+ }
13
+
5
14
  /**
6
15
  * Loads a package.json file from a directory.
7
16
  * @param {string} dir - The directory to look in.