@mgks/docmd 0.2.4 → 0.2.5

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.
@@ -4,7 +4,7 @@ const fs = require('fs-extra');
4
4
  const path = require('path');
5
5
  const readline = require('readline');
6
6
 
7
- const defaultConfigContent = `// config.js: basic config for docmd
7
+ const defaultConfigContent = `// docmd.config.js: basic config for docmd
8
8
  module.exports = {
9
9
  // Core Site Metadata
10
10
  siteTitle: 'docmd',
@@ -108,6 +108,8 @@ module.exports = {
108
108
  { title: 'GitHub', path: 'https://github.com/mgks/docmd', icon: 'github', external: true },
109
109
  { title: 'Support the Project', path: 'https://github.com/sponsors/mgks', icon: 'heart', external: true },
110
110
  ],
111
+
112
+ pageNavigation: true, // Enable previous / next page navigation at the bottom of each page
111
113
 
112
114
  // Sponsor Ribbon Configuration
113
115
  Sponsor: {
@@ -139,7 +141,7 @@ Start writing your Markdown content here.
139
141
  async function initProject() {
140
142
  const baseDir = process.cwd();
141
143
  const docsDir = path.join(baseDir, 'docs');
142
- const configFile = path.join(baseDir, 'config.js');
144
+ const configFile = path.join(baseDir, 'docmd.config.js');
143
145
  const indexMdFile = path.join(docsDir, 'index.md');
144
146
  const assetsDir = path.join(baseDir, 'assets');
145
147
  const assetsCssDir = path.join(assetsDir, 'css');
@@ -154,6 +156,11 @@ async function initProject() {
154
156
 
155
157
  // Check each file individually
156
158
  if (await fs.pathExists(configFile)) {
159
+ existingFiles.push('docmd.config.js');
160
+ }
161
+ // Check for the config.js as well to warn the user
162
+ const oldConfigFile = path.join(baseDir, 'config.js');
163
+ if (await fs.pathExists(oldConfigFile)) {
157
164
  existingFiles.push('config.js');
158
165
  }
159
166
 
@@ -230,14 +237,11 @@ async function initProject() {
230
237
  }
231
238
 
232
239
  // Write config file if it doesn't exist or user confirmed override
233
- if (!await fs.pathExists(configFile)) {
234
- await fs.writeFile(configFile, defaultConfigContent, 'utf8');
235
- console.log('📄 Created `config.js`');
236
- } else if (shouldOverride) {
240
+ if (!await fs.pathExists(configFile) || shouldOverride) {
237
241
  await fs.writeFile(configFile, defaultConfigContent, 'utf8');
238
- console.log('📄 Updated `config.js`');
242
+ console.log(`📄 ${shouldOverride ? 'Updated' : 'Created'} \`docmd.config.js\``);
239
243
  } else {
240
- console.log('⏭️ Skipped existing `config.js`');
244
+ console.log('⏭️ Skipped existing `docmd.config.js`');
241
245
  }
242
246
 
243
247
  // Write index.md file if it doesn't exist or user confirmed override
@@ -14,12 +14,13 @@ async function loadConfig(configPath) {
14
14
  const config = require(absoluteConfigPath);
15
15
 
16
16
  // Basic validation and defaults
17
- if (!config.siteTitle) throw new Error('`siteTitle` is missing in config.js');
17
+ if (!config.siteTitle) throw new Error('`siteTitle` is missing in config file');
18
18
  config.srcDir = config.srcDir || 'docs';
19
19
  config.outputDir = config.outputDir || 'site';
20
20
  config.theme = config.theme || {};
21
21
  config.theme.defaultMode = config.theme.defaultMode || 'light';
22
22
  config.navigation = config.navigation || [{ title: 'Home', path: '/' }];
23
+ config.pageNavigation = config.pageNavigation ?? true;
23
24
 
24
25
  return config;
25
26
  } catch (e) {
@@ -34,6 +34,11 @@ function createMarkdownItInstance(config) {
34
34
  // Conditionally enable highlighting
35
35
  if (config.theme?.codeHighlight !== false) {
36
36
  mdOptions.highlight = function (str, lang) {
37
+ // Handle mermaid diagrams
38
+ if (lang === 'mermaid') {
39
+ return `<pre class="mermaid">${new MarkdownIt().utils.escapeHtml(str)}</pre>`;
40
+ }
41
+
37
42
  if (lang && hljs.getLanguage(lang)) {
38
43
  try {
39
44
  return `<pre class="hljs"><code>${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}</code></pre>`;
@@ -41,6 +46,14 @@ function createMarkdownItInstance(config) {
41
46
  }
42
47
  return `<pre class="hljs"><code>${new MarkdownIt().utils.escapeHtml(str)}</code></pre>`;
43
48
  };
49
+ } else {
50
+ // Even if highlighting is disabled, we need to handle mermaid
51
+ mdOptions.highlight = function (str, lang) {
52
+ if (lang === 'mermaid') {
53
+ return `<pre class="mermaid">${new MarkdownIt().utils.escapeHtml(str)}</pre>`;
54
+ }
55
+ return `<pre><code>${new MarkdownIt().utils.escapeHtml(str)}</code></pre>`;
56
+ };
44
57
  }
45
58
 
46
59
  const md = new MarkdownIt(mdOptions);
@@ -464,6 +477,11 @@ function enhancedTabsRule(state, startLine, endLine, silent) {
464
477
  typographer: true,
465
478
  breaks: true,
466
479
  highlight: function (str, lang) {
480
+ // Handle mermaid diagrams in tabs
481
+ if (lang === 'mermaid') {
482
+ return '<pre class="mermaid">' + MarkdownIt.utils.escapeHtml(str) + '</pre>';
483
+ }
484
+
467
485
  if (lang && hljs.getLanguage(lang)) {
468
486
  try {
469
487
  return '<pre class="hljs"><code>' +
@@ -124,7 +124,7 @@ async function generateHtmlPage(templateData) {
124
124
  prevPage,
125
125
  nextPage,
126
126
  currentPagePath,
127
- headings: headings || [],
127
+ headings: frontmatter.toc !== false ? (headings || []) : [],
128
128
  isActivePage,
129
129
  frontmatter,
130
130
  config: config,
@@ -79,7 +79,7 @@
79
79
  <div class="main-content">
80
80
  <%- content %>
81
81
 
82
- <% if (prevPage || nextPage) { %>
82
+ <% if (config.pageNavigation && (prevPage || nextPage)) { %>
83
83
  <div class="page-navigation">
84
84
  <% if (prevPage) { %>
85
85
  <a href="<%= prevPage.url %>" class="prev-page">
@@ -129,6 +129,10 @@
129
129
  </div>
130
130
 
131
131
  <script src="<%= relativePathToRoot %>assets/js/docmd-main.js"></script>
132
+
133
+ <!-- Mermaid.js for diagram rendering -->
134
+ <script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
135
+ <script src="<%= relativePathToRoot %>assets/js/docmd-mermaid.js"></script>
132
136
 
133
137
  <% (customJsFiles || []).forEach(jsFile => { %>
134
138
  <script src="<%= relativePathToRoot %><%- jsFile.startsWith('/') ? jsFile.substring(1) : jsFile %>"></script>
@@ -15,7 +15,7 @@ function decodeHtmlEntities(html) {
15
15
  const shouldShowToc = typeof isActivePage !== 'undefined' ? isActivePage :
16
16
  (typeof navigationHtml !== 'undefined' && navigationHtml && navigationHtml.includes('class="active"'));
17
17
 
18
- if (shouldShowToc) {
18
+ if (shouldShowToc && !frontmatter?.toc || frontmatter?.toc !== 'false') {
19
19
  // If direct headings aren't available, we'll try to extract them from the content
20
20
  let tocHeadings = [];
21
21
  if (headings && headings.length > 0) {