mrmd-sync 0.3.2 → 0.3.3
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/LICENSE +21 -0
- package/package.json +1 -1
- package/src/index.js +28 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Maxime Rivest
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -30,6 +30,25 @@ import { join, dirname, relative, resolve } from 'path';
|
|
|
30
30
|
import { createHash } from 'crypto';
|
|
31
31
|
import { tmpdir } from 'os';
|
|
32
32
|
|
|
33
|
+
const DOC_EXTENSIONS = ['.md', '.qmd'];
|
|
34
|
+
|
|
35
|
+
function getDocExtension(docName) {
|
|
36
|
+
if (!docName) return '';
|
|
37
|
+
const lower = docName.toLowerCase();
|
|
38
|
+
for (const ext of DOC_EXTENSIONS) {
|
|
39
|
+
if (lower.endsWith(ext)) return ext;
|
|
40
|
+
}
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveDocFilePath(docName, resolvedDir) {
|
|
45
|
+
const hasDocExt = !!getDocExtension(docName);
|
|
46
|
+
if (docName.startsWith('/')) {
|
|
47
|
+
return hasDocExt ? docName : `${docName}.md`;
|
|
48
|
+
}
|
|
49
|
+
return hasDocExt ? join(resolvedDir, docName) : join(resolvedDir, `${docName}.md`);
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
// =============================================================================
|
|
34
53
|
// PID FILE - Prevents multiple instances on same directory
|
|
35
54
|
// =============================================================================
|
|
@@ -689,16 +708,8 @@ export function createServer(options = {}) {
|
|
|
689
708
|
const mutex = new AsyncMutex();
|
|
690
709
|
|
|
691
710
|
// Support absolute paths for files outside the docs directory
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if (docName.startsWith('/')) {
|
|
695
|
-
// Absolute path - use directly
|
|
696
|
-
isAbsolutePath = true;
|
|
697
|
-
filePath = docName.endsWith('.md') ? docName : `${docName}.md`;
|
|
698
|
-
} else {
|
|
699
|
-
// Relative path - join with docs directory
|
|
700
|
-
filePath = join(resolvedDir, docName.endsWith('.md') ? docName : `${docName}.md`);
|
|
701
|
-
}
|
|
711
|
+
const isAbsolutePath = docName.startsWith('/');
|
|
712
|
+
const filePath = resolveDocFilePath(docName, resolvedDir);
|
|
702
713
|
|
|
703
714
|
// For snapshots, always use the snapshot dir with a safe name
|
|
704
715
|
const safeSnapshotName = docName.replace(/\//g, '__').replace(/^_+/, '');
|
|
@@ -924,7 +935,10 @@ export function createServer(options = {}) {
|
|
|
924
935
|
// FILE WATCHER
|
|
925
936
|
// =============================================================================
|
|
926
937
|
|
|
927
|
-
const watcher = watch(
|
|
938
|
+
const watcher = watch([
|
|
939
|
+
join(resolvedDir, '**/*.md'),
|
|
940
|
+
join(resolvedDir, '**/*.qmd'),
|
|
941
|
+
], {
|
|
928
942
|
ignoreInitial: true,
|
|
929
943
|
awaitWriteFinish: { stabilityThreshold: 300 },
|
|
930
944
|
ignored: [
|
|
@@ -952,7 +966,9 @@ export function createServer(options = {}) {
|
|
|
952
966
|
|
|
953
967
|
watcher.on('add', async (filePath) => {
|
|
954
968
|
const relativePath = relative(resolvedDir, filePath);
|
|
955
|
-
const docName = relativePath.
|
|
969
|
+
const docName = relativePath.toLowerCase().endsWith('.md')
|
|
970
|
+
? relativePath.replace(/\.md$/i, '')
|
|
971
|
+
: relativePath;
|
|
956
972
|
|
|
957
973
|
if (docs.has(docName)) {
|
|
958
974
|
const { content, error } = safeReadFile(filePath, maxFileSize);
|