Add frontpage explaining the project and providing links

This commit is contained in:
Daniel Siepmann 2023-08-23 12:28:42 +02:00
parent 0d0866be1e
commit c634827af7
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
8 changed files with 167 additions and 6 deletions

View file

@ -2,12 +2,14 @@
use DanielSiepmann\FediverseFeedWrappers\RequestHandler; use DanielSiepmann\FediverseFeedWrappers\RequestHandler;
use DanielSiepmann\FediverseFeedWrappers\WrapperRegistry; use DanielSiepmann\FediverseFeedWrappers\WrapperRegistry;
use DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage;
use DanielSiepmann\FediverseFeedWrappers\Wrapper\GitHubTypo3; use DanielSiepmann\FediverseFeedWrappers\Wrapper\GitHubTypo3;
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
(new RequestHandler( (new RequestHandler(
new WrapperRegistry([ new WrapperRegistry([
'' => Frontpage::class,
'GitHubTypo3' => GitHubTypo3::class, 'GitHubTypo3' => GitHubTypo3::class,
]) ])
))->handleRequest(); ))->handleRequest();

View file

@ -38,8 +38,8 @@ class RequestHandler
*/ */
public function handleRequest(): void public function handleRequest(): void
{ {
$content = $this->wrapperRegistry->get($_GET['feed'] ?? '')->handle(); $wrapper = $this->wrapperRegistry->get($_GET['feed'] ?? '');
header('content-type: application/xml;charset=utf-8'); header('content-type: ' . $wrapper->contentType() . ';charset=utf-8');
echo $content; echo $wrapper->content();
} }
} }

40
src/Wrapper/Frontpage.php Normal file
View file

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace DanielSiepmann\FediverseFeedWrappers\Wrapper;
use DanielSiepmann\FediverseFeedWrappers\WrapperInterface;
class Frontpage implements WrapperInterface
{
public function contentType(): string
{
return 'text/html';
}
public function content(): string
{
$content = '
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fediverse Wrapper by Daniel Siepmann</title>
</head>
<body>
<h1>Fediverse Wrapper by Daniel Siepmann</h1>
<p>This is a small project that allows to wrap other sources to be used by the Fediverse.</p>
<p>I use it myself in order to mirror the wrapped feeds from my friendi.ca instance.</p>
<p>A list of the TYPO3 mirror accounts is available at: <a href="https://daniel-siepmann.de/typo3-fediverse-news-accounts.html">https://daniel-siepmann.de/typo3-fediverse-news-accounts.html</a>.</p>
<p>The repository of the source code is available here: <a href="https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers">https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers</a>.</p>
</body>
</html>
';
$content = str_replace(' ', '', $content);
$content = trim($content);
return $content . PHP_EOL;
}
}

View file

@ -36,13 +36,18 @@ class GitHubTypo3 implements WrapperInterface
$this->url = $url; $this->url = $url;
} }
public function contentType(): string
{
return 'application/xml';
}
/** /**
* We don't want the full commit messag within each feed item. * We don't want the full commit messag within each feed item.
* *
* Instead we are only interested in first row. * Instead we are only interested in first row.
* Interested people can head over to the actual URL for full info. * Interested people can head over to the actual URL for full info.
*/ */
public function handle(): string public function content(): string
{ {
$content = new DOMDocument(); $content = new DOMDocument();
$content->loadXML(file_get_contents($this->url)); $content->loadXML(file_get_contents($this->url));

View file

@ -25,5 +25,6 @@ namespace DanielSiepmann\FediverseFeedWrappers;
interface WrapperInterface interface WrapperInterface
{ {
public function handle(): string; public function contentType(): string;
public function content(): string;
} }

View file

@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fediverse Wrapper by Daniel Siepmann</title>
</head>
<body>
<h1>Fediverse Wrapper by Daniel Siepmann</h1>
<p>This is a small project that allows to wrap other sources to be used by the Fediverse.</p>
<p>I use it myself in order to mirror the wrapped feeds from my friendi.ca instance.</p>
<p>A list of the TYPO3 mirror accounts is available at: <a href="https://daniel-siepmann.de/typo3-fediverse-news-accounts.html">https://daniel-siepmann.de/typo3-fediverse-news-accounts.html</a>.</p>
<p>The repository of the source code is available here: <a href="https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers">https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers</a>.</p>
</body>
</html>

View file

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
namespace DanielSiepmann\FediverseFeedWrappers\Tests\Unit\Wrapper;
use DanielSiepmann\FediverseFeedWrappers\WrapperInterface;
use DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage;
use PHPUnit\Framework\TestCase;
/**
* @covers \DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage
*/
class FrontpageTest extends TestCase
{
/**
* @test
*/
public function canBeCreated(): void
{
$subject = new Frontpage();
self::assertInstanceOf(
Frontpage::class,
$subject
);
}
/**
* @test
*/
public function isInstanceOfWrapperInterface(): void
{
$subject = new Frontpage();
self::assertInstanceOf(
WrapperInterface::class,
$subject
);
}
/**
* @test
*/
public function returnsContentType(): void
{
$subject = new Frontpage();
self::assertSame(
'text/html',
$subject->contentType()
);
}
/**
* @test
*/
public function returnsContent(): void
{
$subject = new Frontpage();
self::assertStringEqualsFile(
__DIR__ . '/Assertions/Frontpage.html',
$subject->content()
);
}
}

View file

@ -58,6 +58,19 @@ class GitHubTypo3Test extends TestCase
); );
} }
/**
* @test
*/
public function returnsContentType(): void
{
$subject = new GitHubTypo3();
self::assertSame(
'application/xml',
$subject->contentType()
);
}
/** /**
* @test * @test
*/ */
@ -69,7 +82,7 @@ class GitHubTypo3Test extends TestCase
self::assertStringEqualsFile( self::assertStringEqualsFile(
__DIR__ . '/Assertions/GitHubTypo3.atom', __DIR__ . '/Assertions/GitHubTypo3.atom',
$subject->handle() $subject->content()
); );
} }
} }