Browse Source

implement getLinks method

main
ghost 9 months ago
parent
commit
590096afef
  1. 20
      README.md
  2. 29
      src/Dokuwiki/Reader.php

20
README.md

@ -75,15 +75,33 @@ echo $reader->toGemini( @@ -75,15 +75,33 @@ echo $reader->toGemini(
Get document title
```
echo $reader->getH1(
$gemini = $reader->toGemini(
file_get_contents(
'/host/data/pages/index.txt'
)
);
echo $reader->getH1(
$gemini
);
```
#### Reader::getLinks
Get document links
```
$gemini = $reader->toGemini(
file_get_contents(
'/host/data/pages/index.txt'
)
);
echo $reader->getLinks(
$gemini
);
```
### Filesystem
Provides methods for simple and secure interaction with DokuWiki file storage

29
src/Dokuwiki/Reader.php

@ -246,12 +246,12 @@ class Reader @@ -246,12 +246,12 @@ class Reader
);
}
public function getH1(string $data): ?string
public function getH1(string $gemini, ?string $regex = '/^[\s]?#([^#]+)/'): ?string
{
foreach ((array) explode(PHP_EOL, $data) as $line)
foreach ((array) explode(PHP_EOL, $gemini) as $line)
{
preg_match_all(
'/^[\s]?#([^#]+)/',
$regex,
$line,
$matches
);
@ -266,4 +266,27 @@ class Reader @@ -266,4 +266,27 @@ class Reader
}
}
}
public function getLinks(string $gemini, ?string $regex = '/[A-z]+:\/\/\S+/'): array
{
$links = [];
preg_match_all(
$regex,
$gemini,
$matches
);
if (!empty($matches[0]))
{
foreach ((array) $matches[0] as $link)
{
$links[] = trim(
$link
);
}
}
return $links;
}
}
Loading…
Cancel
Save