Skip to content

Commit

Permalink
use hugo for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Nov 15, 2023
1 parent d82f169 commit 08e6b63
Show file tree
Hide file tree
Showing 99 changed files with 17,640 additions and 56 deletions.
2 changes: 2 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,6 @@ COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
# Prod Caddy image
FROM caddy_base AS caddy_prod

WORKDIR /srv
COPY --from=php_prod --link /srv/app/public public/
COPY --from=docs --link /srv docs/
13 changes: 9 additions & 4 deletions api/docker/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ log {
output file /var/log/caddy/access.log
}

route {
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
header ?Permissions-Policy "browsing-topics=()"
# route {
# # Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
# header ?Permissions-Policy "browsing-topics=()"
#
# reverse_proxy http://{$PWA_UPSTREAM}
# }

reverse_proxy http://{$PWA_UPSTREAM}
route /docs/* {
root * /docs
file_server
}
35 changes: 17 additions & 18 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ version: "3.4"

# Development environment override
services:
php:
build:
context: ./api
target: php_dev
volumes:
- ./api:/srv/app
- ./api/docker/php/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
# If you develop on Mac or Windows you can remove the vendor/ directory
# from the bind-mount for better performance by enabling the next line:
#- /srv/app/vendor
environment:
# See https://xdebug.org/docs/all_settings#mode
XDEBUG_MODE: "${XDEBUG_MODE:-off}"
extra_hosts:
# Ensure that host.docker.internal is correctly defined on Linux
- host.docker.internal:host-gateway
# php:
# build:
# context: ./api
# target: php_dev
# volumes:
# - ./api:/srv/app
# - ./api/docker/php/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
# # If you develop on Mac or Windows you can remove the vendor/ directory
# # from the bind-mount for better performance by enabling the next line:
# #- /srv/app/vendor
# environment:
# # See https://xdebug.org/docs/all_settings#mode
# XDEBUG_MODE: "${XDEBUG_MODE:-off}"
# extra_hosts:
# # Ensure that host.docker.internal is correctly defined on Linux
# - host.docker.internal:host-gateway

pwa:
build:
Expand All @@ -34,10 +34,9 @@ services:
caddy:
command: [ "caddy", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]
build:
context: api/
context: docs/
target: caddy_base
volumes:
- ./api/public:/srv/app/public:ro
- ./api/docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
environment:
MERCURE_EXTRA_DIRECTIVES: demo
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ version: "3.4"

# Production environment override
services:
php:
build:
context: ./api
target: php_prod
environment:
APP_SECRET: ${APP_SECRET}
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET}
# php:
# build:
# context: ./api
# target: php_prod
# environment:
# APP_SECRET: ${APP_SECRET}
# MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET}

pwa:
build:
Expand Down
45 changes: 21 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
version: "3.4"

services:
php:
image: ${IMAGES_PREFIX:-}app-php
depends_on:
- database
restart: unless-stopped
volumes:
- php_socket:/var/run/php
healthcheck:
interval: 10s
timeout: 3s
retries: 3
start_period: 30s
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|caddy$$
MERCURE_URL: ${CADDY_MERCURE_URL:-http://caddy/.well-known/mercure}
MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}

# php:
# image: ${IMAGES_PREFIX:-}app-php
# depends_on:
# - database
# restart: unless-stopped
# volumes:
# - php_socket:/var/run/php
# healthcheck:
# interval: 10s
# timeout: 3s
# retries: 3
# start_period: 30s
# environment:
# DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}
# TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
# TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|caddy$$
# MERCURE_URL: ${CADDY_MERCURE_URL:-http://caddy/.well-known/mercure}
# MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
# MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}

pwa:
image: ${IMAGES_PREFIX:-}app-pwa
Expand All @@ -31,9 +30,6 @@ services:

caddy:
image: ${IMAGES_PREFIX:-}app-caddy
depends_on:
- php
- pwa
environment:
PWA_UPSTREAM: pwa:3000
BUCKET_S3_UPSTREAM: http://storage.googleapis.com
Expand All @@ -42,8 +38,9 @@ services:
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
restart: unless-stopped
depends_on:
- pwa
volumes:
- php_socket:/var/run/php
- caddy_data:/data
- caddy_config:/config
ports:
Expand Down
5 changes: 5 additions & 0 deletions docs/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public
node_modules
docs.temp
core.temp
tools/pdg
8 changes: 8 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.phive
core.temp
docs.temp
public
content/*
node_modules
data/*
tools/pdg
Empty file added docs/.hugo_build.lock
Empty file.
28 changes: 28 additions & 0 deletions docs/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
# Debug
{$CADDY_DEBUG}
}

{$SERVER_NAME}

log {
output file /var/log/caddy/access.log
}

redir /docs /docs/3.2/distribution
redir /docs/ /docs/3.2/distribution

@version path_regexp version (/docs/[^/]+)$
redir @version {re.version.1}/distribution

handle_path /docs/* {
root * /home/soyuka/forks/website/docs/public
file_server
}

handle {
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
header ?Permissions-Policy "browsing-topics=()"

reverse_proxy http://{$PWA_UPSTREAM}
}
30 changes: 30 additions & 0 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM composer/composer:2-bin AS composer_upstream

FROM php as php_documentation_generator

RUN apt-get update && apt-get install -y gnupg git libzip-dev zip
WORKDIR /srv
ADD . /srv
COPY --from=composer_upstream --link /composer /usr/bin/composer
COPY --from=phario/phive:0.15.2 --link /usr/local/bin/phive /usr/bin/phive
RUN docker-php-ext-install zip
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN bash tools/get-docs.sh \
&& bash tools/get-core-docs.sh

FROM node:lts-alpine as build
WORKDIR /srv
COPY --from=php_documentation_generator /srv /srv
RUN npm install && node tools/menu.mjs

FROM golang:1.21 as docs
WORKDIR /srv
COPY --from=build /srv /srv
VOLUME /srv/public
RUN go install github.com/gohugoio/[email protected]
RUN hugo

FROM caddy:2-alpine AS caddy_base
COPY --from=docs --link /srv/public /srv/docs
COPY ./Caddyfile /etc/caddy/Caddyfile
25 changes: 25 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# API Platform documentation website

## Build

```
npm install
# fetches api-platform/docs
bash tools/get-docs.sh
# fetches api-platform/core for reference and guides
bash tools/get-core-docs.sh
# builds the config/_default/menu.toml according to the outline.yaml from api-platform/docs
node tools/menu.mjs
# build our tailwind theme
cd themes/api-platform
npm install
npm run build
# run hugo to build public/
cd ../../
hugo
```

## Dev

In `themes/api-platform` run `npm run build -- --watch`
Run `hugo serve`
72 changes: 72 additions & 0 deletions docs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# The Schema Generator

`schema` is a command line tool part of [the API Platform framework](https://api-platform.com) that instantly generates a set
of PHP classes from [RDF](https://en.wikipedia.org/wiki/Resource_Description_Framework) vocabularies such as (but not limited to)
[Schema.org](https://schema.org) or [ActivityStreams](https://www.w3.org/TR/activitystreams-core/).
Alternatively, it can generate PHP classes from an [OpenAPI](https://www.openapis.org/) documentation.

[Find and browse](https://lov.linkeddata.es/) (or create) a vocabulary that fits your needs, choose the types and properties you need, run our code generator and you're done!
Alternatively, design your API with tools like [Stoplight](https://stoplight.io/), export the OpenAPI documentation, run our code generator and your API is ready!

![Stoplight](images/stoplight.png)

You get a fully featured PHP data model including:

* A set of PHP entities with properties, constants (enum values), getters, setters, adders and removers. The class
hierarchy provided by the vocabulary will be translated to a PHP class hierarchy with parents as `abstract` classes.
The generated code complies with [PSR](http://www.php-fig.org/) coding standards;
* Full, high-quality PHPDoc and type declarations for classes, properties, constants and methods extracted from the vocabulary;
* Doctrine ORM or MongoDB ODM attributes mapping including database columns / fields with type guessing, relations with cardinality guessing,
smart class inheritance (through the `#[MappedSuperclass]` or `#[InheritanceType]` attributes depending on if the resource is used in a relation);
* Data validation through [Symfony Validator](https://symfony.com/doc/current/book/validation.html) attributes including enum support (choices) and check for required properties;
* API Platform attributes;
* Interfaces and [Doctrine `ResolveTargetEntityListener`](https://www.doctrine-project.org/projects/doctrine-orm/en/current/cookbook/resolve-target-entity-listener.html)
support;
* Custom PHP namespace support;
* List of values provided the vocabulary with [PHP Enum](https://github.com/myclabs/php-enum) classes.

Bonus:

* The code generator is fully configurable and extendable. All features can be deactivated (e.g., the Doctrine mapping generator)
and a custom generator can be added;
* The code generator can load previously generated files and add new changes while keeping the user-added ones;
* The generated code can be used as is in a [Symfony](https://symfony.com) app (but it will work too in a raw PHP project
or any other framework including [Laravel](https://laravel.com) and [Zend Framework](http://framework.zend.com/)).

## What Is Schema.org?

Schema.org is a vocabulary representing common data structures and their relations. Schema.org can be exposed as [JSON-LD](https://en.wikipedia.org/wiki/JSON-LD),
[microdata](https://en.wikipedia.org/wiki/Microdata_(HTML)) and [RDF](https://en.wikipedia.org/wiki/Resource_Description_Framework).
Extracting semantical data exposed in the Schema.org vocabulary is supported by a growing number of companies including
Google (Search, Gmail), Yahoo!, Bing and Yandex.

## Why Use Schema.org Data to Generate a PHP Model?

### Don't Reinvent the Wheel

Data models provided by Schema.org are popular and were proven efficient. They cover a broad spectrum of topics including
creative works, e-commerce, events, medicine, social networking, people, postal addresses, organization data, places or reviews.
Schema.org has its root in a ton of preexisting well-designed vocabularies and is
successfully used by more and more websites and applications.

Pick schemas applicable to your application, generate your PHP model, then customize and specialize it to fit your needs.

### Improve SEO and User Experience

Adding Schema.org markup to websites and apps increases their ranking in search engines results and enables awesome features
such as [Google Rich Snippets](https://support.google.com/webmasters/answer/99170?hl=en) and [Gmail markup](https://developers.google.com/gmail/markup/overview).

Mapping your app data model to Schema.org structures can be tedious. When using the generator, your data model will be
derived from Schema.org. Adding microdata markup to your templates or serializing your data as JSON-LD will not require
specific mapping nor adaptation. It's a matter of minutes.

### Be Ready for The Future

Schema.org improves the interoperability of your applications. Used with hypermedia technologies such as [Hydra](http://www.hydra-cg.com/)
it's a big step towards the semantic and machine-readable web.
It opens the way to generic web API clients able to extract and process data from any website or app using such technologies.

## Documentation

* [Getting Started](getting-started.md)
* [Configuration](configuration.md)
5 changes: 5 additions & 0 deletions docs/archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
+++
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
date = {{ .Date }}
draft = true
+++
Loading

0 comments on commit 08e6b63

Please sign in to comment.