Skip to content

Commit 857a799

Browse files
committed
Added file ID docs.
1 parent 5d414d6 commit 857a799

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ $manager->addFile('Title of the file', '/path/to/documentation.md');
5555
->display();
5656
```
5757

58-
## Adding files
58+
## Adding single files
5959

6060
Single files can be added using `addFile()`. This allows specifying the
6161
name that the file will be listed under in the UI.
@@ -69,6 +69,8 @@ $manager = new DocsManager();
6969
$manager->addFile('Name of the file', '/path/to/file.md');
7070
```
7171

72+
## Adding folders
73+
7274
To add multiple files, use the `addFolder()` method:
7375

7476
```php
@@ -95,6 +97,33 @@ $manager = new DocsManager();
9597
$manager->addFolder('/path/to/files', false, 'txt');
9698
```
9799

100+
> NOTE: Adding files this way means you cannot specify file IDs (see "Consistent
101+
file permalinks"). Please double-check that this is okay in your use case.
102+
103+
## Consistent file permalinks
104+
105+
By default, the viewer will create an ID for each file based on its absolute
106+
path on disk. This means that the ID will change if the file is moved at some
107+
point, or if the viewer is used on different systems. Sharing permalinks risks
108+
the links being broken at some point.
109+
110+
To avoid this issue, specify a unique file ID manually when adding single files:
111+
112+
```php
113+
use Mistralys\MarkdownViewer\DocsManager;
114+
115+
$manager = new DocsManager();
116+
117+
$manager->addFile(
118+
'Name of the file',
119+
'/path/to/file.md',
120+
'(Unique file ID)'
121+
);
122+
```
123+
124+
The ID can be any string; the viewer uses it to create the hash that is used in the UI
125+
to identify the files. This way, permalinks will always stay consistent.
126+
98127
## Dark mode
99128

100129
To turn on dark mode, simply use `makeDarkMode()`:

0 commit comments

Comments
 (0)