Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

index-files.pl 800 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  1. #!/usr/bin/env perl
  2. use v5.32;
  3. use utf8;
  4. use warnings;
  5. use File::Path qw(make_path);
  6. my $outdir = $ENV{QUARTO_PROJECT_OUTPUT_DIR};
  7. $outdir = "_site" if (!defined $outdir);
  8. my @pages = glob "data/*.qmd";
  9. my $n = @pages;
  10. print "scanning $n doc pages, writing to $outdir\n";
  11. make_path($outdir) or die "$outdir: $!" if ! -d $outdir;
  12. open(my $ofh, ">$outdir/files.json") or die "$outdir/files.json: $!";
  13. print $ofh "{\n";
  14. my $first = 1;
  15. foreach my $page (@pages) {
  16. open(my $fh, "<$page") or die "$page: $!";
  17. while (<$fh>) {
  18. if (m/^:::\s*\{.*file="([^"]+)".*\}/) {
  19. print "$page: $1\n";
  20. print $ofh ",\n" if !$first;
  21. print $ofh "\"$1\": {\"page\": \"$page\"}";
  22. $first = 0;
  23. }
  24. }
  25. close $fh;
  26. }
  27. print $ofh "\n}\n";
  28. close $ofh;
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...