Merge remote-tracking branch 'remotes/upstream/master'
This commit is contained in:
commit
4686d48902
85
.github/workflows/php.yml
vendored
Normal file
85
.github/workflows/php.yml
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
name: CI
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
max-parallel: 15
|
||||
matrix:
|
||||
# TODO : enable tests on windows
|
||||
operating-system: [ubuntu-latest, macOS-latest]
|
||||
php-versions: ['7.2', '7.3', '7.4']
|
||||
exclude:
|
||||
- operating-system: macos-latest
|
||||
php-versions: 7.4
|
||||
|
||||
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@master
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
extension-csv: mbstring, dom, intl
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress --no-suggest
|
||||
|
||||
- name: Install tools
|
||||
run: ./scripts/install_tools.sh
|
||||
|
||||
- name: Run test suite
|
||||
run: composer run-script test
|
||||
|
||||
sonarcloud:
|
||||
name: "SonarCloud"
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request'
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@master
|
||||
with:
|
||||
php-version: 7.4
|
||||
extension-csv: mbstring, dom, intl
|
||||
coverage: pcov
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress --no-suggest
|
||||
|
||||
- name: Install tools
|
||||
run: ./scripts/install_tools.sh
|
||||
|
||||
- name: Run test suite
|
||||
run: composer run-script test -- --coverage-clover=coverage.clover --log-junit=test-report.xml
|
||||
|
||||
- name: Fix reports
|
||||
run: scripts/fix_reports.sh
|
||||
|
||||
- name: SonarCloud Scan
|
||||
uses: SonarSource/sonarcloud-github-action@v1.1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
|
||||
documentation:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'dauxio/daux.io' && github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress --no-suggest
|
||||
- name: Generate documentation
|
||||
run: bin/daux generate --value html.plausible_domain=daux.io
|
||||
- uses: JamesIves/github-pages-deploy-action@2.0.3
|
||||
env:
|
||||
FOLDER: "static"
|
||||
BRANCH: gh-pages
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -5,6 +5,11 @@ node_modules
|
||||
static
|
||||
|
||||
/vendor
|
||||
/build
|
||||
.phpunit.result.cache
|
||||
.php_cs.cache
|
||||
coverage.clover
|
||||
test-report.xml
|
||||
|
||||
/prettier.config.js
|
||||
/.eslintrc.js
|
||||
|
28
.php_cs
Normal file
28
.php_cs
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()
|
||||
->exclude('vendor')
|
||||
->exclude('templates')
|
||||
->in(__DIR__)
|
||||
;
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'@PHP70Migration' => true,
|
||||
'@PHP71Migration' => true,
|
||||
'@PhpCsFixer' => true,
|
||||
'explicit_string_variable' => false,
|
||||
'single_blank_line_before_namespace' => false,
|
||||
'no_short_echo_tag' => false,
|
||||
'blank_line_after_opening_tag' => false,
|
||||
'yoda_style' => false,
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
'php_unit_internal_class' => false,
|
||||
'php_unit_test_class_requires_covers' => false,
|
||||
'phpdoc_align' => false,
|
||||
'multiline_whitespace_before_semicolons' => false,
|
||||
'ordered_class_elements' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'method']
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
37
.travis.yml
37
.travis.yml
@ -1,37 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
- '7.3'
|
||||
- nightly
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
|
||||
before_script:
|
||||
- composer install --dev --prefer-source
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit --coverage-clover=coverage.clover
|
||||
|
||||
after_script:
|
||||
- wget https://scrutinizer-ci.com/ocular.phar
|
||||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: "Deploy Documentation"
|
||||
php: "7.3"
|
||||
script: skip
|
||||
before_deploy:
|
||||
- composer install
|
||||
- bin/daux generate
|
||||
deploy:
|
||||
provider: pages
|
||||
local_dir: static
|
||||
skip_cleanup: true
|
||||
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
|
||||
on:
|
||||
branch: master
|
@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
- Using welcoming and inclusive language
|
||||
- Being respectful of differing viewpoints and experiences
|
||||
- Gracefully accepting constructive criticism
|
||||
- Focusing on what is best for the community
|
||||
- Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
- The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
- Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM composer:1.7.2 AS composer
|
||||
FROM composer:1.10.5 AS composer
|
||||
|
||||
FROM php:7-stretch
|
||||
|
||||
|
162
README.md
162
README.md
@ -1,51 +1,48 @@
|
||||
# Daux.io
|
||||
|
||||
|
||||
[![Latest Version](https://img.shields.io/github/release/dauxio/daux.io.svg?style=flat-square)](https://github.com/dauxio/daux.io/releases)
|
||||
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/dauxio/daux.io/blob/master/LICENSE.md)
|
||||
[![Build Status](https://img.shields.io/travis/dauxio/daux.io/master.svg?style=flat-square)](https://travis-ci.org/dauxio/daux.io)
|
||||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/dauxio/daux.io/CI?style=flat-square)
|
||||
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/dauxio/daux.io.svg?style=flat-square)](https://scrutinizer-ci.com/g/dauxio/daux.io/code-structure)
|
||||
[![Quality Score](https://img.shields.io/scrutinizer/g/dauxio/daux.io.svg?style=flat-square)](https://scrutinizer-ci.com/g/dauxio/daux.io)
|
||||
[![Total Downloads](https://img.shields.io/packagist/dt/daux/daux.io.svg?style=flat-square)](https://packagist.org/packages/daux/daux.io)
|
||||
|
||||
|
||||
**Daux.io** is a documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly. It helps you create great looking documentation in a developer friendly way.
|
||||
|
||||
## Features
|
||||
|
||||
* 100% Mobile Responsive
|
||||
* CommonMark compliant (a Markdown specification)
|
||||
* Supports Markdown tables
|
||||
* Auto created homepage/landing page
|
||||
* Auto Syntax Highlighting
|
||||
* Auto Generated Navigation
|
||||
* 4 Built-In Themes or roll your own
|
||||
* Functional, Flat Design Style
|
||||
* Shareable/Linkable SEO Friendly URLs
|
||||
* Built On Bootstrap
|
||||
* No Build Step
|
||||
* Git/SVN Friendly
|
||||
* Supports Google Analytics and Piwik Analytics
|
||||
* Optional code float layout
|
||||
* Static Output Generation
|
||||
- 100% Mobile Responsive
|
||||
- CommonMark compliant (a Markdown specification)
|
||||
- Supports Markdown tables
|
||||
- Auto created homepage/landing page
|
||||
- Auto Syntax Highlighting
|
||||
- Auto Generated Navigation
|
||||
- 4 Built-In Themes or roll your own
|
||||
- Functional, Flat Design Style
|
||||
- Shareable/Linkable SEO Friendly URLs
|
||||
- Built On Bootstrap
|
||||
- No Build Step
|
||||
- Git/SVN Friendly
|
||||
- Supports Google Analytics and Piwik Analytics
|
||||
- Optional code float layout
|
||||
- Static Output Generation
|
||||
|
||||
## Demos
|
||||
|
||||
This is a list of sites using Daux.io:
|
||||
|
||||
- With a custom theme:
|
||||
* [Crafty](https://swissquote.github.io/crafty)
|
||||
* [Pixolution flow](https://docs.pixolution.org)
|
||||
* [Soisy](https://doc.soisy.it/)
|
||||
* [Vulkan Tutorial](https://vulkan-tutorial.com)
|
||||
* [3Q](https://docs.3q.video/)
|
||||
- With the default Theme
|
||||
* [Daux.io](https://daux.io/)
|
||||
* [DoctrineWatcher](https://dsentker.github.io/WatcherDocumentation/)
|
||||
* [DrupalGap](http://docs.drupalgap.org/8/)
|
||||
* [ICADMIN: An admin panel powered by CodeIgniter.](http://istocode.com/shared/ic-admin/)
|
||||
* [Munee: Standalone PHP 5.3 Asset Optimisation & Manipulation](http://mun.ee)
|
||||
* [Nuntius: A PHP framework for bots](https://roysegall.github.io/nuntius-bot/)
|
||||
- With a custom theme:
|
||||
- [Crafty](https://swissquote.github.io/crafty)
|
||||
- [Pixolution flow](https://docs.pixolution.org) \* [Soisy](https://doc.soisy.it/)
|
||||
- [Vulkan Tutorial](https://vulkan-tutorial.com) \* [3Q](https://docs.3q.video/)
|
||||
- [The Advanced RSS Environment](https://thearsse.com/manual/)
|
||||
- With the default Theme
|
||||
- [Daux.io](https://daux.io/)
|
||||
_ [DoctrineWatcher](https://dsentker.github.io/WatcherDocumentation/)
|
||||
_ [DrupalGap](http://docs.drupalgap.org/8/)
|
||||
- [ICADMIN: An admin panel powered by CodeIgniter.](http://istocode.com/shared/ic-admin/)
|
||||
- [Munee: Standalone PHP 5.3 Asset Optimisation & Manipulation](http://mun.ee)
|
||||
- [Nuntius: A PHP framework for bots](https://roysegall.github.io/nuntius-bot/)
|
||||
|
||||
Do you use Daux.io? Send me a pull request or open an [issue](https://github.com/dauxio/daux.io/issues) and I will add you to the list.
|
||||
|
||||
@ -100,18 +97,18 @@ You must use underscores instead of spaces. Here are some example file names and
|
||||
|
||||
**Good:**
|
||||
|
||||
* 01_Getting_Started.md = Getting Started
|
||||
* API_Calls.md = API Calls
|
||||
* 200_Something_Else-Cool.md = Something Else-Cool
|
||||
* _5_Ways_to_Be_Happy.md = 5 Ways To Be Happy
|
||||
- 01_Getting_Started.md = Getting Started
|
||||
- API_Calls.md = API Calls
|
||||
- 200_Something_Else-Cool.md = Something Else-Cool
|
||||
- \_5_Ways_to_Be_Happy.md = 5 Ways To Be Happy
|
||||
|
||||
**Bad:**
|
||||
|
||||
* File Name With Space.md = FAIL
|
||||
- File Name With Space.md = FAIL
|
||||
|
||||
## Sorting
|
||||
|
||||
To sort your files and folders in a specific way, you can prefix them with a number and underscore, e.g. `/docs/01_Hello_World.md` and `/docs/05_Features.md` This will list *Hello World* before *Features*, overriding the default alpha-numeric sorting. The numbers will be stripped out of the navigation and urls. For the file `6 Ways to Get Rich`, you can use `/docs/_6_Ways_to_Get_Rich.md`
|
||||
To sort your files and folders in a specific way, you can prefix them with a number and underscore, e.g. `/docs/01_Hello_World.md` and `/docs/05_Features.md` This will list _Hello World_ before _Features_, overriding the default alpha-numeric sorting. The numbers will be stripped out of the navigation and urls. For the file `6 Ways to Get Rich`, you can use `/docs/_6_Ways_to_Get_Rich.md`
|
||||
|
||||
## Landing page
|
||||
|
||||
@ -119,9 +116,9 @@ If you want to create a beautiful landing page for your project, simply create a
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Daux.io",
|
||||
"tagline": "The Easiest Way To Document Your Project",
|
||||
"image": "app.png"
|
||||
"title": "Daux.io",
|
||||
"tagline": "The Easiest Way To Document Your Project",
|
||||
"image": "app.png"
|
||||
}
|
||||
```
|
||||
|
||||
@ -137,37 +134,41 @@ To customize the look and feel of your documentation, you can create a `config.j
|
||||
The `config.json` file is a simple JSON object that you can use to change some of the basic settings of the documentation.
|
||||
|
||||
### Title
|
||||
|
||||
Change the title bar in the docs
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Daux.io"
|
||||
"title": "Daux.io"
|
||||
}
|
||||
```
|
||||
|
||||
### Themes
|
||||
|
||||
We have 4 built-in Bootstrap themes. To use one of the themes, just set the `theme` option to one of the following:
|
||||
|
||||
* daux-blue
|
||||
* daux-green
|
||||
* daux-navy
|
||||
* daux-red
|
||||
- daux-blue
|
||||
- daux-green
|
||||
- daux-navy
|
||||
- daux-red
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "theme": "daux-green" }
|
||||
"html": { "theme": "daux-green" }
|
||||
}
|
||||
```
|
||||
|
||||
### More options
|
||||
|
||||
Many other options are available:
|
||||
- [Global options](http://daux.io/Configuration/index)
|
||||
- [HTML Options](http://daux.io/Configuration/Html_export)
|
||||
- [Confluence options](http://daux.io/Configuration/Confluence_upload)
|
||||
|
||||
- [Global options](http://daux.io/Configuration/index)
|
||||
- [HTML Options](http://daux.io/Configuration/Html_export)
|
||||
- [Confluence options](http://daux.io/Configuration/Confluence_upload)
|
||||
|
||||
## Running Remotely
|
||||
|
||||
Copy the files from the repo to a web server that can run PHP 5.4 or greater.
|
||||
Copy the files from the repo to a web server that can run PHP 7.2.0 or newer.
|
||||
|
||||
## Running Locally
|
||||
|
||||
@ -192,8 +193,8 @@ daux --source=docs --destination=static
|
||||
|
||||
If you have set up a local or remote IIS web site, you may need a `web.config` with:
|
||||
|
||||
* A rewrite configuration, for handling clean urls.
|
||||
* A mime type handler for less files, if using a custom theme.
|
||||
- A rewrite configuration, for handling clean urls.
|
||||
- A mime type handler for less files, if using a custom theme.
|
||||
|
||||
### Clean URLs
|
||||
|
||||
@ -201,45 +202,44 @@ The `web.config` needs an entry for `<rewrite>` under `<system.webServer>`:
|
||||
|
||||
```xml
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="Main Rule" stopProcessing="true">
|
||||
<match url=".*" />
|
||||
<conditions logicalGrouping="MatchAll">
|
||||
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
|
||||
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
|
||||
</conditions>
|
||||
<action type="Rewrite" url="index.php" appendQueryString="false" />
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
</system.webServer>
|
||||
<system.webServer>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="Main Rule" stopProcessing="true">
|
||||
<match url=".*" />
|
||||
<conditions logicalGrouping="MatchAll">
|
||||
<add
|
||||
input="{REQUEST_FILENAME}"
|
||||
matchType="IsFile"
|
||||
negate="true"
|
||||
/>
|
||||
<add
|
||||
input="{REQUEST_FILENAME}"
|
||||
matchType="IsDirectory"
|
||||
negate="true"
|
||||
/>
|
||||
</conditions>
|
||||
<action
|
||||
type="Rewrite"
|
||||
url="index.php"
|
||||
appendQueryString="false"
|
||||
/>
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
```
|
||||
|
||||
To use clean URLs on IIS 6, you will need to use a custom URL rewrite module, such as [URL Rewriter](http://urlrewriter.net/).
|
||||
|
||||
## Docker
|
||||
|
||||
A docker configuration is also provided to run daux within a container, you can either run daux with php5 or php7.
|
||||
|
||||
```
|
||||
cd docker
|
||||
docker-compose -f docker-compose.7.yml up -d
|
||||
```
|
||||
|
||||
You can then point your browser to http://localhost:8086
|
||||
|
||||
## PHP Requirements
|
||||
|
||||
Daux.io is compatible with PHP 7.1.3 and up.
|
||||
|
||||
The reason is because some dependencies we have (mainly Symfony and Guzzle) do not support PHP 5.6 anymore.
|
||||
Daux.io is compatible with the [officially supported](https://www.php.net/supported-versions.php) PHP versions; 7.2.0 and up.
|
||||
|
||||
### Extensions
|
||||
|
||||
PHP Needs the following extension to work : `php-mbstring` and `php-xml`.
|
||||
Daux.io needs the following PHP extensions to work : `php-mbstring` and `php-xml`.
|
||||
|
||||
If you encounter an error similar to `utf8_decode() not found` this means that you're missing the `php-xml` package.
|
||||
|
||||
|
@ -17,18 +17,19 @@
|
||||
],
|
||||
"bin": ["bin/daux"],
|
||||
"require": {
|
||||
"php": ">=7.1.3",
|
||||
"php": ">=7.2",
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
"league/commonmark": "^0.18",
|
||||
"league/commonmark": "^1.0.0",
|
||||
"league/plates": "~3.1",
|
||||
"myclabs/deep-copy": "^1.5",
|
||||
"symfony/console": "^4.0",
|
||||
"symfony/http-foundation": "^4.0",
|
||||
"scrivo/highlight.php": "^9.15",
|
||||
"symfony/console": "^5.0",
|
||||
"symfony/http-foundation": "^5.0",
|
||||
"symfony/mime": "^5.0",
|
||||
"symfony/polyfill-intl-icu": "^1.10",
|
||||
"symfony/process": "^4.0",
|
||||
"webuni/commonmark-table-extension": "0.9.*",
|
||||
"symfony/process": "^5.0",
|
||||
"webuni/front-matter": "^1.0.0",
|
||||
"scrivo/highlight.php": "^9.15"
|
||||
"ext-json": "*"
|
||||
},
|
||||
"suggest":{
|
||||
"ext-intl": "Allows to translate the modified at date"
|
||||
@ -42,10 +43,12 @@
|
||||
"justinwalsh/daux.io": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~7.4",
|
||||
"mikey179/vfsstream": "^1.6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit"
|
||||
"test": "build/phpunit",
|
||||
"test:coverage-html": "build/phpunit --coverage-html=build/coverage",
|
||||
"lint": "build/php-cs-fixer fix --config=.php_cs --dry-run -v",
|
||||
"lint:fix": "build/php-cs-fixer fix --config=.php_cs"
|
||||
}
|
||||
}
|
||||
|
1975
composer.lock
generated
1975
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,5 @@
|
||||
module.exports = {
|
||||
browsers:
|
||||
"> 0.25%, Edge >= 15, Safari >= 10, iOS >= 10, Chrome >= 56, Firefox >= 51, IE >= 11, not op_mini all",
|
||||
browsers: "defaults, not op_mini all",
|
||||
presets: [
|
||||
"@swissquote/crafty-preset-babel",
|
||||
"@swissquote/crafty-runner-rollup",
|
||||
@ -23,11 +22,13 @@ module.exports = {
|
||||
js: {
|
||||
search: {
|
||||
runner: "rollup",
|
||||
format: "iife",
|
||||
source: "src/js/search/index.js",
|
||||
destination: "daux_libraries/search.min.js"
|
||||
},
|
||||
theme_daux: {
|
||||
runner: "rollup",
|
||||
format: "iife",
|
||||
source: "src/js/theme_daux/index.js",
|
||||
destination: "themes/daux/js/daux.min.js"
|
||||
}
|
||||
@ -58,5 +59,9 @@ module.exports = {
|
||||
destination: "themes/daux_singlepage/css/main.min.css",
|
||||
watch: ["src/css/**/*.scss"]
|
||||
}
|
||||
},
|
||||
postcss(crafty, config, bundle) {
|
||||
// Add postcss-page-break
|
||||
config.processor("postcss-page-break").before("autoprefixer");
|
||||
}
|
||||
};
|
||||
|
2
daux_libraries/search.min.js
vendored
2
daux_libraries/search.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -12,7 +12,7 @@ services:
|
||||
- phpserver
|
||||
|
||||
phpserver:
|
||||
image: php:7.0-fpm
|
||||
image: php:7.4-fpm
|
||||
working_dir: /var/www/
|
||||
volumes:
|
||||
- ../:/var/www/
|
||||
|
@ -6,49 +6,48 @@
|
||||
|
||||
### For Authors
|
||||
|
||||
* [Auto Generated Navigation / Page sorting](01_Features/Navigation_and_Sorting.md)
|
||||
* [Internal documentation links](01_Features/Internal_links.md)
|
||||
* [CommonMark compliant](01_Features/CommonMark_compliant.md)
|
||||
* [Auto created homepage/landing page](01_Features/Landing_page.md)
|
||||
* [Multiple Output Formats](01_Features/Multiple_Output_Formats.md)
|
||||
* [Multiple Languages Support](01_Features/Multilanguage.md)
|
||||
* [No Build Step](01_Features/Live_mode.md)
|
||||
* [Static Output Generation](01_Features/Static_Site_Generation.md)
|
||||
* [Table of Contents](01_Features/Table_of_contents.md)
|
||||
- [Auto Generated Navigation / Page sorting](01_Features/Navigation_and_Sorting.md)
|
||||
- [Internal documentation links](01_Features/Internal_links.md)
|
||||
- [CommonMark compliant](01_Features/CommonMark_compliant.md)
|
||||
- [Auto created homepage/landing page](01_Features/Landing_page.md)
|
||||
- [Multiple Output Formats](01_Features/Multiple_Output_Formats.md)
|
||||
- [Multiple Languages Support](01_Features/Multilanguage.md)
|
||||
- [No Build Step](01_Features/Live_mode.md)
|
||||
- [Static Output Generation](01_Features/Static_Site_Generation.md)
|
||||
- [Table of Contents](01_Features/Table_of_contents.md)
|
||||
|
||||
### For Developers
|
||||
|
||||
* [Auto Syntax Highlighting](01_Features/Auto_Syntax_Highlight.md)
|
||||
* [Extend Daux.io with Processors](01_For_Developers/Creating_a_Processor.md)
|
||||
* Full access to the internal API to create new pages programatically
|
||||
* Work with pages metadata
|
||||
- [Auto Syntax Highlighting](01_Features/Auto_Syntax_Highlight.md)
|
||||
- [Extend Daux.io with Processors](01_For_Developers/Creating_a_Processor.md)
|
||||
- Full access to the internal API to create new pages programatically
|
||||
- Work with pages metadata
|
||||
|
||||
### For Marketing
|
||||
|
||||
* 100% Mobile Responsive
|
||||
* 4 Built-In Themes or roll your own
|
||||
* Functional, Flat Design Style
|
||||
* Optional code float layout
|
||||
* Shareable/Linkable SEO Friendly URLs
|
||||
* Supports Google Analytics and Piwik Analytics
|
||||
- 100% Mobile Responsive
|
||||
- 4 Built-In Themes or roll your own
|
||||
- Functional, Flat Design Style
|
||||
- Optional code float layout
|
||||
- Shareable/Linkable SEO Friendly URLs
|
||||
- Supports Google Analytics and Piwik Analytics
|
||||
|
||||
## Demos
|
||||
|
||||
This is a list of sites using Daux.io:
|
||||
|
||||
- With a custom theme:
|
||||
* [Crafty](https://swissquote.github.io/crafty)
|
||||
* [Pixolution flow](https://docs.pixolution.org)
|
||||
* [Soisy](https://doc.soisy.it/)
|
||||
* [Vulkan Tutorial](https://vulkan-tutorial.com)
|
||||
* [3Q](https://docs.3q.video/)
|
||||
- With the default Theme
|
||||
* [Daux.io](https://daux.io/)
|
||||
* [DoctrineWatcher](https://dsentker.github.io/WatcherDocumentation/)
|
||||
* [DrupalGap](http://docs.drupalgap.org/8/)
|
||||
* [ICADMIN: An admin panel powered by CodeIgniter.](http://istocode.com/shared/ic-admin/)
|
||||
* [Munee: Standalone PHP 5.3 Asset Optimisation & Manipulation](http://mun.ee)
|
||||
* [Nuntius: A PHP framework for bots](https://roysegall.github.io/nuntius-bot/)
|
||||
- With a custom theme:
|
||||
- [Crafty](https://swissquote.github.io/crafty)
|
||||
- [Pixolution flow](https://docs.pixolution.org) \* [Soisy](https://doc.soisy.it/)
|
||||
- [Vulkan Tutorial](https://vulkan-tutorial.com)
|
||||
- [3Q](https://docs.3q.video/)
|
||||
- With the default Theme
|
||||
- [Daux.io](https://daux.io/)
|
||||
_ [DoctrineWatcher](https://dsentker.github.io/WatcherDocumentation/)
|
||||
_ [DrupalGap](http://docs.drupalgap.org/8/)
|
||||
- [ICADMIN: An admin panel powered by CodeIgniter.](http://istocode.com/shared/ic-admin/)
|
||||
- [Munee: Standalone PHP 5.3 Asset Optimisation & Manipulation](http://mun.ee)
|
||||
- [Nuntius: A PHP framework for bots](https://roysegall.github.io/nuntius-bot/)
|
||||
|
||||
Do you use Daux.io? Send us a pull request or open an [issue](https://github.com/dauxio/daux.io/issues) and I will add you to the list.
|
||||
|
||||
@ -81,10 +80,10 @@ docker run --rm -it -w /build -v "$PWD":/build daux/daux.io daux
|
||||
|
||||
Any parameter valid in the PHP version is valid in the Docker version
|
||||
|
||||
|
||||
### Writing pages
|
||||
|
||||
Creating new pages is very easy:
|
||||
|
||||
1. Create a markdown file (`*.md` or `*.markdown`)
|
||||
2. Start writing
|
||||
|
||||
@ -98,14 +97,14 @@ You must use underscores instead of spaces. Here are some example file names and
|
||||
|
||||
**Good:**
|
||||
|
||||
* 01_Getting_Started.md = Getting Started
|
||||
* API_Calls.md = API Calls
|
||||
* 200_Something_Else-Cool.md = Something Else-Cool
|
||||
* _5_Ways_to_Be_Happy.md = 5 Ways To Be Happy
|
||||
- 01_Getting_Started.md = Getting Started
|
||||
- API_Calls.md = API Calls
|
||||
- 200_Something_Else-Cool.md = Something Else-Cool
|
||||
- \_5_Ways_to_Be_Happy.md = 5 Ways To Be Happy
|
||||
|
||||
**Bad:**
|
||||
|
||||
* File Name With Space.md = FAIL
|
||||
- File Name With Space.md = FAIL
|
||||
|
||||
### See your pages
|
||||
|
||||
@ -129,9 +128,9 @@ Upload your files to an apache / nginx server and see your documentation
|
||||
|
||||
Daux.io is extendable and comes by default with three export formats:
|
||||
|
||||
- Export to HTML, same as the website, but can be hosted without PHP.
|
||||
- Export all documentation in a single HTML page
|
||||
- Upload to your Atlassian Confluence server.
|
||||
- Export to HTML, same as the website, but can be hosted without PHP.
|
||||
- Export all documentation in a single HTML page
|
||||
- Upload to your Atlassian Confluence server.
|
||||
|
||||
[See a detailed feature comparison matrix](01_Features/Multiple_Output_Formats.md)
|
||||
|
||||
@ -145,20 +144,13 @@ Now that you got the basics, you can also [see what you can configure](05_Config
|
||||
|
||||
## PHP Requirements
|
||||
|
||||
Daux.io is compatible with PHP 7.1.3 and up.
|
||||
|
||||
The reason is because some dependencies we have (mainly Symfony and Guzzle) do not support PHP 5.6 anymore.
|
||||
Daux.io is compatible with the [officially supported](https://www.php.net/supported-versions.php) PHP versions; 7.2.0 and up.
|
||||
|
||||
### Extensions
|
||||
|
||||
PHP Needs the following extension to work : `php-mbstring` and `php-xml`.
|
||||
|
||||
If you encounter an error similar to `utf8_decode() not found` this means that you're missing the `php-xml` package. (We've seen it happen only on PHP 7)
|
||||
|
||||
## Known Issues
|
||||
|
||||
- __Windows UTF-8 files support__ Files with UTF-8 characters cannot be handled on windows with PHP5, PHP7 should work fine.
|
||||
Daux.io needs the following PHP extensions to work : `php-mbstring` and `php-xml`.
|
||||
|
||||
If you encounter an error similar to `utf8_decode() not found` this means that you're missing the `php-xml` package.
|
||||
|
||||
## Support
|
||||
|
||||
|
@ -1,17 +1,14 @@
|
||||
|
||||
As we support CommonMark, a broad range of markdown features is available to you.
|
||||
|
||||
Many of the features shown below were known as Github Flavored Markdown.
|
||||
|
||||
|
||||
We all like making lists
|
||||
------------------------
|
||||
## We all like making lists
|
||||
|
||||
The above header should be an H2 tag. Now, for a list of fruits:
|
||||
|
||||
* Red Apples
|
||||
* Purple Grapes
|
||||
* Green Kiwifruits
|
||||
- Red Apples
|
||||
- Purple Grapes
|
||||
- Green Kiwifruits
|
||||
|
||||
Let's get crazy:
|
||||
|
||||
@ -27,18 +24,17 @@ Let's get crazy:
|
||||
|
||||
What about some code **in** a list? That's insane, right?
|
||||
|
||||
1. In Ruby you can map like this:
|
||||
1. In Ruby you can map like this:
|
||||
|
||||
['a', 'b'].map { |x| x.uppercase }
|
||||
|
||||
2. In Rails, you can do a shortcut:
|
||||
2. In Rails, you can do a shortcut:
|
||||
|
||||
['a', 'b'].map(&:uppercase)
|
||||
|
||||
Some people seem to like definition lists
|
||||
|
||||
I am a robot
|
||||
------------
|
||||
## I am a robot
|
||||
|
||||
Maybe you want to print `robot` to the console 1000 times. Why not?
|
||||
|
||||
@ -54,8 +50,7 @@ How about we throw some angle braces and ampersands in there?
|
||||
© 2004 Foo Corporation
|
||||
</div>
|
||||
|
||||
Set in stone
|
||||
------------
|
||||
## Set in stone
|
||||
|
||||
Preformatted blocks are useful for ASCII art:
|
||||
|
||||
@ -73,8 +68,7 @@ Preformatted blocks are useful for ASCII art:
|
||||
___|_____________
|
||||
</pre>
|
||||
|
||||
Playing the blame game
|
||||
----------------------
|
||||
## Playing the blame game
|
||||
|
||||
If you need to blame someone, the best way to do so is by quoting them:
|
||||
|
||||
@ -92,26 +86,23 @@ Or perhaps someone a little less eloquent:
|
||||
> just put me under the spot here, and maybe I'm not as quick on my feet
|
||||
> as I should be in coming up with one.
|
||||
|
||||
Table for two
|
||||
-------------
|
||||
## Table for two
|
||||
|
||||
ID | Name | Rank
|
||||
---|:------:|------:
|
||||
1 | Tom Preston-Werner | Awesome
|
||||
2 | Albert Einstein | Nearly as awesome
|
||||
| ID | Name | Rank |
|
||||
| --- | :----------------: | ----------------: |
|
||||
| 1 | Tom Preston-Werner | Awesome |
|
||||
| 2 | Albert Einstein | Nearly as awesome |
|
||||
|
||||
Crazy linking action
|
||||
--------------------
|
||||
## Crazy linking action
|
||||
|
||||
I get 10 times more traffic from [Google] [1] than from
|
||||
[Yahoo] [2] or [MSN] [3].
|
||||
I get 10 times more traffic from [Google][1] than from
|
||||
[Yahoo][2] or [MSN][3].
|
||||
|
||||
[1]: http://google.com/ "Google"
|
||||
[2]: http://search.yahoo.com/ "Yahoo Search"
|
||||
[3]: http://search.msn.com/ "MSN Search"
|
||||
[1]: http://google.com/ "Google"
|
||||
[2]: http://search.yahoo.com/ "Yahoo Search"
|
||||
[3]: http://search.msn.com/ "MSN Search"
|
||||
|
||||
Images
|
||||
------
|
||||
## Images
|
||||
|
||||
Here's an image.
|
||||
|
||||
@ -119,4 +110,4 @@ Here's an image.
|
||||
|
||||
Note: to use images on a landing page (index.md), prefix the image URL with the name of the directory it appears in, omitting the numerical prefix used to order the sections. For example in this section, to display this image on the landing page (index.md), the URL for the image would be "Features/sampleimage.png" to display the same image.
|
||||
|
||||
*View the [source of this content](https://github.com/dauxio/daux.io/blob/master/docs/01_Features/CommonMark_compliant.md).*
|
||||
_View the [source of this content](https://github.com/dauxio/daux.io/blob/master/docs/01_Features/CommonMark_compliant.md)._
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
As you can see on the top of this page, you can add "Edit on Github" links to your pages, this feature can be enabled with a single parameter.
|
||||
|
||||
The value has to be the path to the root of your documentation folder in your repository.
|
||||
@ -7,12 +6,11 @@ In the value you see below, Daux's documentation is in the `docs` folder in the
|
||||
|
||||
Daux.io will handle the rest
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"edit_on_github": "dauxio/daux.io/blob/master/docs"
|
||||
}
|
||||
"html": {
|
||||
"edit_on_github": "dauxio/daux.io/blob/master/docs"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -22,14 +20,13 @@ While GitHub is the most popular, it isn't the only, collaborative VCS out there
|
||||
|
||||
As long as you can refer your files by a URL, you can create an edit link for your VCS with the following configuration:
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"edit_on": {
|
||||
"name": "Bitbucket",
|
||||
"basepath": "https://bitbucket.org/dauxio/daux.io/src/master/docs"
|
||||
"html": {
|
||||
"edit_on": {
|
||||
"name": "Bitbucket",
|
||||
"basepath": "https://bitbucket.org/dauxio/daux.io/src/master/docs"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -2,9 +2,9 @@ If you want to create a beautiful landing page for your project, create a `_inde
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Daux.io",
|
||||
"tagline": "The Easiest Way To Document Your Project",
|
||||
"image": "app.png"
|
||||
"title": "Daux.io",
|
||||
"tagline": "The Easiest Way To Document Your Project",
|
||||
"image": "app.png"
|
||||
}
|
||||
```
|
||||
|
||||
@ -14,8 +14,8 @@ To disable the automatic landing page, you can set `auto_landing` to false in th
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"auto_landing": false
|
||||
}
|
||||
"html": {
|
||||
"auto_landing": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -10,7 +10,6 @@ The easiest is to use PHP's built-in server.
|
||||
|
||||
For that i've included a short command, run `daux serve` in the projects folder to start the local web server. By default the server will run at: <a href="http://localhost:8085" target="_blank">http://localhost:8085</a>
|
||||
|
||||
|
||||
## Running Remotely
|
||||
|
||||
### Clean URLs configuration
|
||||
@ -20,15 +19,15 @@ To enable the same, set the toggle in the `config.json` file in the `/docs` fold
|
||||
|
||||
```json
|
||||
{
|
||||
"live": {
|
||||
"clean_urls": true
|
||||
}
|
||||
"live": {
|
||||
"clean_urls": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Apache
|
||||
|
||||
Copy the files from the repo to a web server that can run PHP 5.6 or greater.
|
||||
Copy the files from the repo to a web server that can run PHP 7.2.0 or newer.
|
||||
|
||||
There is an included `.htaccess` for Apache web server.
|
||||
|
||||
@ -70,8 +69,8 @@ server {
|
||||
|
||||
If you have set up a local or remote IIS web site, you may need a `web.config` with:
|
||||
|
||||
* A rewrite configuration, for handling clean urls.
|
||||
* A mime type handler for less files, if using a custom theme.
|
||||
- A rewrite configuration, for handling clean urls.
|
||||
- A mime type handler for less files, if using a custom theme.
|
||||
|
||||
### Clean URLs
|
||||
|
||||
@ -79,20 +78,32 @@ The `web.config` needs an entry for `<rewrite>` under `<system.webServer>`:
|
||||
|
||||
```xml
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="Main Rule" stopProcessing="true">
|
||||
<match url=".*" />
|
||||
<conditions logicalGrouping="MatchAll">
|
||||
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
|
||||
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
|
||||
</conditions>
|
||||
<action type="Rewrite" url="index.php" appendQueryString="false" />
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
</system.webServer>
|
||||
<system.webServer>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="Main Rule" stopProcessing="true">
|
||||
<match url=".*" />
|
||||
<conditions logicalGrouping="MatchAll">
|
||||
<add
|
||||
input="{REQUEST_FILENAME}"
|
||||
matchType="IsFile"
|
||||
negate="true"
|
||||
/>
|
||||
<add
|
||||
input="{REQUEST_FILENAME}"
|
||||
matchType="IsDirectory"
|
||||
negate="true"
|
||||
/>
|
||||
</conditions>
|
||||
<action
|
||||
type="Rewrite"
|
||||
url="index.php"
|
||||
appendQueryString="false"
|
||||
/>
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
```
|
||||
|
||||
|
@ -4,11 +4,12 @@ Add this to your config.json :
|
||||
|
||||
```json
|
||||
{
|
||||
"languages": { "en": "English", "de": "German" }
|
||||
"languages": { "en": "English", "de": "German" }
|
||||
}
|
||||
```
|
||||
|
||||
You will the need separate directories for each language in `docs/` folder.
|
||||
|
||||
```
|
||||
├── docs/
|
||||
│ ├── _index.md
|
||||
|
@ -1,21 +1,21 @@
|
||||
Daux.io is extendable and comes by default with three export formats:
|
||||
|
||||
- Export to HTML
|
||||
- Export all documentation in a single HTML page
|
||||
- Upload to your Atlassian Confluence server
|
||||
- Export to HTML
|
||||
- Export all documentation in a single HTML page
|
||||
- Upload to your Atlassian Confluence server
|
||||
|
||||
## Feature Matrix
|
||||
|
||||
Feature | HTML | Single Page HTML | Confluence
|
||||
--------------:|:----:|:----------------:|:----------:
|
||||
Multilanguage | √ | X (Planned) | X
|
||||
Landing Pages | √ | X | X
|
||||
Index Pages | √ | √ | √
|
||||
Internal Links | √ | X (Planned) | √
|
||||
Code Highlight | √ | X (Planned) | √ (Using macros)
|
||||
Live Mode | √ | X | X
|
||||
Pages Ordering | √ | √ | X (API Limitation)
|
||||
Google / Piwik analytics | √ | √ | √ (Configured on Conflence)
|
||||
| Feature | HTML | Single Page HTML | Confluence |
|
||||
| -----------------------: | :--: | :--------------: | :-------------------------: |
|
||||
| Multilanguage | √ | X (Planned) | X |
|
||||
| Landing Pages | √ | X | X |
|
||||
| Index Pages | √ | √ | √ |
|
||||
| Internal Links | √ | X (Planned) | √ |
|
||||
| Code Highlight | √ | X (Planned) | √ (Using macros) |
|
||||
| Live Mode | √ | X | X |
|
||||
| Pages Ordering | √ | √ | X (API Limitation) |
|
||||
| Google / Piwik analytics | √ | √ | √ (Configured on Conflence) |
|
||||
|
||||
## Confluence Example
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
## Navigation
|
||||
|
||||
The navigation is generated automatically with all pages that end with `.md` or `.markdown`
|
||||
@ -12,7 +11,7 @@ For example, `/docs/02_Examples` has a landing page for that section since there
|
||||
## Sorting
|
||||
|
||||
To sort your files and folders in a specific way, you can prefix them with a number and underscore, e.g. `/docs/01_Hello_World.md` and `/docs/05_Features.md`.
|
||||
This will list *Hello World* before *Features*, overriding the default alpha-numeric sorting.
|
||||
This will list _Hello World_ before _Features_, overriding the default alpha-numeric sorting.
|
||||
The numbers will be stripped out of the navigation and urls. For the file `6 Ways to Get Rich`, you can use `/docs/_6_Ways_to_Get_Rich.md`
|
||||
|
||||
You might also wish to stick certain links to the bottom of a page.
|
||||
@ -23,10 +22,10 @@ It works the same for files prefixed with `+`.
|
||||
|
||||
Page order priorities are like this:
|
||||
|
||||
- `+` in front of the filename and numbers in front
|
||||
- `+` in front of the filename
|
||||
- The index page
|
||||
- Numbers in the front
|
||||
- Pages without prefix
|
||||
- `-` in front of the filename and numbers in front
|
||||
- `-` in front of the filename
|
||||
- `+` in front of the filename and numbers in front
|
||||
- `+` in front of the filename
|
||||
- The index page
|
||||
- Numbers in the front
|
||||
- Pages without prefix
|
||||
- `-` in front of the filename and numbers in front
|
||||
- `-` in front of the filename
|
||||
|
@ -6,8 +6,8 @@ To enable the generated search, you can set `search` to true in the `html` secti
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"search": true
|
||||
}
|
||||
"html": {
|
||||
"search": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -1,9 +1,8 @@
|
||||
If you don't want to serve the live version of your site, you can also generate files, these can be one of the three supported formats :
|
||||
|
||||
If you don't want to serve the live version of your site, you can also generate files, these can be one of the three supported formats :
|
||||
|
||||
- HTML output
|
||||
- Single page HTML output
|
||||
- Atlassian Confluence upload
|
||||
- HTML output
|
||||
- Single page HTML output
|
||||
- Atlassian Confluence upload
|
||||
|
||||
Generating a complete set of pages, with navigation
|
||||
|
||||
@ -32,7 +31,7 @@ daux --format=html
|
||||
|
||||
### Specify a processor
|
||||
|
||||
A processor can be specified through the `--processor` option, this should be the name of a class inside the `Todaymade\Daux\Extension` namespace.
|
||||
A processor can be specified through the `--processor` option, this should be the name of a class inside the `Todaymade\Daux\Extension` namespace.
|
||||
|
||||
By running :
|
||||
|
||||
|
@ -18,10 +18,8 @@ You can enable this feature in your configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"auto_toc": true
|
||||
}
|
||||
"html": {
|
||||
"auto_toc": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,3 @@
|
||||
### This is a landing page for the Examples section
|
||||
|
||||
Adding a landing page is pretty simple, all you need to do is add an "index.md" file to the related folder.
|
@ -1,21 +1,23 @@
|
||||
__Table of contents__
|
||||
**Table of contents**
|
||||
|
||||
[TOC]
|
||||
|
||||
## Configuring the connection
|
||||
|
||||
The connection requires three parameters `base_url`, `user` and `pass`. While `user` and `pass` don't really need an explanation, for `base_url` you need to set the path to the server without `rest/api`, this will be added automatically.
|
||||
|
||||
```json
|
||||
{
|
||||
"confluence": {
|
||||
"base_url": "http://my_confluence_server.com/",
|
||||
"user" : "my_username",
|
||||
"pass" : "my_password"
|
||||
}
|
||||
"confluence": {
|
||||
"base_url": "http://my_confluence_server.com/",
|
||||
"user": "my_username",
|
||||
"pass": "my_password"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Where to upload
|
||||
|
||||
Now that the connection is defined, you need to tell it where you want your documentation to be uploaded.
|
||||
|
||||
For that you need a `space_id` (name that appears at the beginning of the urls) and an `ancestor_id`; the id of the page that will be the parent of the documentation's homepage.
|
||||
@ -24,10 +26,10 @@ You can obtain the `ancestor_id` id by editing the page you want to define as a
|
||||
|
||||
```json
|
||||
{
|
||||
"confluence": {
|
||||
"space_id": "my_space",
|
||||
"ancestor_id": 50370632
|
||||
}
|
||||
"confluence": {
|
||||
"space_id": "my_space",
|
||||
"ancestor_id": 50370632
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -36,20 +38,22 @@ You can also provide a `root_id` instead of an `ancestor_id` in this case, you s
|
||||
You can use that when you're uploading your documentation to the root of a Confluence Space or if your page already exists.
|
||||
|
||||
## Prefix
|
||||
|
||||
Because confluence can't have two pages with the same name in a space, I recommend you define a prefix for your pages.
|
||||
|
||||
```json
|
||||
{
|
||||
"confluence": { "prefix": "DAUX -" }
|
||||
"confluence": { "prefix": "DAUX -" }
|
||||
}
|
||||
```
|
||||
|
||||
## Update threshold
|
||||
|
||||
To make the upload quicker, we try to determine if a page changed or not, first with a strict comparison and if it's not completely identical, we compute the difference.
|
||||
|
||||
```json
|
||||
{
|
||||
"confluence": { "update_threshold": 1 }
|
||||
"confluence": { "update_threshold": 1 }
|
||||
}
|
||||
```
|
||||
|
||||
@ -59,22 +63,22 @@ By default the threshold is 2%.
|
||||
|
||||
Setting the value to `0` disables the feature altogether.
|
||||
|
||||
|
||||
## Delete old pages
|
||||
|
||||
When a page is renamed, there is no way to tell it was renamed, so when uploading to Confluence, the page will be uploaded and the old page will stay here.
|
||||
|
||||
By default, it will inform you that some pages aren't needed anymore and you can delete them by hand.
|
||||
|
||||
```json
|
||||
{
|
||||
"confluence": { "delete": true }
|
||||
"confluence": { "delete": true }
|
||||
}
|
||||
```
|
||||
|
||||
By setting `delete` to `true` (or running `daux` with the `--delete` flag) you tell the generator that it can safely delete the pages.
|
||||
|
||||
|
||||
## Information message
|
||||
|
||||
When you create your page. there is no indication that the upload process will override the content of the pages.
|
||||
|
||||
It happens sometimes that users edit the pages to add / fix an information.
|
||||
@ -83,9 +87,9 @@ You can add a text in a "information" macro on top of the document by setting th
|
||||
|
||||
```json
|
||||
{
|
||||
"confluence": {
|
||||
"header": "These pages are updated automatically, your changes will be overriden."
|
||||
}
|
||||
"confluence": {
|
||||
"header": "These pages are updated automatically, your changes will be overriden."
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -1,24 +1,26 @@
|
||||
__Table of contents__
|
||||
**Table of contents**
|
||||
|
||||
[TOC]
|
||||
|
||||
## Analytics
|
||||
|
||||
### Google Analytics
|
||||
|
||||
This will embed the google analytics tracking code.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "google_analytics": "UA-XXXXXXXXX-XX" }
|
||||
"html": { "google_analytics": "UA-XXXXXXXXX-XX" }
|
||||
}
|
||||
```
|
||||
|
||||
### Piwik Analytics
|
||||
|
||||
This will embed the piwik tracking code.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "piwik_analytics": "my-url-for-piwik.com" }
|
||||
"html": { "piwik_analytics": "my-url-for-piwik.com" }
|
||||
}
|
||||
```
|
||||
|
||||
@ -26,110 +28,130 @@ You can Also give a specific Piwik ID as well.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "piwik_analytics_id": "43" }
|
||||
"html": { "piwik_analytics_id": "43" }
|
||||
}
|
||||
```
|
||||
|
||||
### Plausible Analytics
|
||||
|
||||
This will embed the https://plausible.io/ tracking code.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "plausible_domain": "daux.io" }
|
||||
}
|
||||
```
|
||||
|
||||
## Automatic Table of Contents
|
||||
|
||||
You can add a table of contents on each page automatically, read about it [here](../01_Features/Table_of_contents.md)
|
||||
|
||||
|
||||
## Buttons
|
||||
|
||||
You can add buttons to the landing page.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"buttons": {
|
||||
"My Website": "http://example.com"
|
||||
"html": {
|
||||
"buttons": {
|
||||
"My Website": "http://example.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Breadcrumb titles
|
||||
|
||||
Daux.io provides the option to present page titles as breadcrumb navigation.
|
||||
You can *optionally* specify the separator used for breadcrumbs.
|
||||
You can _optionally_ specify the separator used for breadcrumbs.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"breadcrumbs": true,
|
||||
"breadcrumb_separator" : " > "
|
||||
}
|
||||
"html": {
|
||||
"breadcrumbs": true,
|
||||
"breadcrumb_separator": " > "
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Date Modified
|
||||
|
||||
By default, daux.io will display the last modified time as reported by the system underneath the title for each document.
|
||||
To disable this, change the option in your config.json to `false`.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "date_modified": false }
|
||||
"html": { "date_modified": false }
|
||||
}
|
||||
```
|
||||
|
||||
## GitHub Repo
|
||||
|
||||
Add a 'Fork me on GitHub' ribbon.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "repo": "dauxio/daux.io" }
|
||||
"html": { "repo": "dauxio/daux.io" }
|
||||
}
|
||||
```
|
||||
|
||||
## Inherit Index
|
||||
|
||||
This feature will instructs the navigation generator to seek the first available file to use when there is no index in a folder.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "inherit_index": true }
|
||||
"html": { "inherit_index": true }
|
||||
}
|
||||
```
|
||||
|
||||
## Jump buttons
|
||||
|
||||
You can have previous/next buttons on each page.
|
||||
They can be disabled by setting `jump_buttons` to `false`.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "jump_buttons": false }
|
||||
"html": { "jump_buttons": false }
|
||||
}
|
||||
```
|
||||
|
||||
## Landing page
|
||||
|
||||
The automatic landing page can be disabled through the `auto_landing` option, read about it [here](../01_Features/Landing_page.md)
|
||||
|
||||
## Links
|
||||
|
||||
Include custom links in the sidebar.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": {
|
||||
"links": {
|
||||
"GitHub Repo": "https://github.com/dauxio/daux.io",
|
||||
"Help/Support/Bugs": "https://github.com/dauxio/daux.io/issues",
|
||||
"Made by Todaymade": "http://todaymade.com"
|
||||
"html": {
|
||||
"links": {
|
||||
"GitHub Repo": "https://github.com/dauxio/daux.io",
|
||||
"Help/Support/Bugs": "https://github.com/dauxio/daux.io/issues",
|
||||
"Made by Todaymade": "http://todaymade.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Search
|
||||
|
||||
Daux has an embedded search engine read all about it [here](../01_Features/Search.md)
|
||||
|
||||
## Themes
|
||||
|
||||
We have 4 built-in Bootstrap themes. To use one of the themes, just set the `theme` option to one of the following:
|
||||
|
||||
* daux-blue
|
||||
* daux-green
|
||||
* daux-navy
|
||||
* daux-red
|
||||
- daux-blue
|
||||
- daux-green
|
||||
- daux-navy
|
||||
- daux-red
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "theme": "daux-blue" }
|
||||
"html": { "theme": "daux-blue" }
|
||||
}
|
||||
```
|
||||
|
||||
@ -137,25 +159,27 @@ To use a custom theme, just copy over the theme folder into the `themes` directo
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "theme": "new-theme" }
|
||||
"html": { "theme": "new-theme" }
|
||||
}
|
||||
```
|
||||
|
||||
## Toggling Code Blocks
|
||||
|
||||
Some users might wish to hide the code blocks & view just the documentation.
|
||||
By setting the `toggle_code` property to `true`, you can offer a toggle button on the page.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "toggle_code": true }
|
||||
"html": { "toggle_code": true }
|
||||
}
|
||||
```
|
||||
|
||||
## Twitter
|
||||
|
||||
Include twitter follow buttons in the sidebar.
|
||||
|
||||
```json
|
||||
{
|
||||
"html": { "twitter": ["justin_walsh", "todaymade"] }
|
||||
"html": { "twitter": ["justin_walsh", "todaymade"] }
|
||||
}
|
||||
```
|
||||
|
@ -1,91 +1,100 @@
|
||||
To customize the look and feel of your documentation, you can create a `config.json` file in the of the `/docs` folder. The `config.json` file is a JSON object that you can use to change some of the basic settings of the documentation.
|
||||
|
||||
__Table of contents__
|
||||
**Table of contents**
|
||||
|
||||
[TOC]
|
||||
|
||||
### Title
|
||||
|
||||
Change the title bar in the docs
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Daux.io"
|
||||
"title": "Daux.io"
|
||||
}
|
||||
```
|
||||
|
||||
### Tagline
|
||||
|
||||
Change the tagline bar in the docs
|
||||
|
||||
```json
|
||||
{
|
||||
"tagline": "The Easiest Way To Document Your Project"
|
||||
"tagline": "The Easiest Way To Document Your Project"
|
||||
}
|
||||
```
|
||||
|
||||
### Author
|
||||
|
||||
Change the documentation's author
|
||||
|
||||
```json
|
||||
{
|
||||
"author": "Stéphane Goetz"
|
||||
"author": "Stéphane Goetz"
|
||||
}
|
||||
```
|
||||
|
||||
### Image
|
||||
|
||||
An image to show on the landing page. A relative path from the documentation root.
|
||||
|
||||
```json
|
||||
{
|
||||
"image": "image.png"
|
||||
"image": "image.png"
|
||||
}
|
||||
```
|
||||
|
||||
### Format
|
||||
|
||||
Change the output format. It is recommended you set only formats that support the live mode as this will also
|
||||
be read by the integrated web server. And you set the other formats (like confluence) only by command line
|
||||
|
||||
```json
|
||||
{
|
||||
"format": "html"
|
||||
"format": "html"
|
||||
}
|
||||
```
|
||||
|
||||
- __html__ with [its options](./Html_export.md)
|
||||
- __confluence__ with [its options](./Confluence_upload.md)
|
||||
- **html** with [its options](./Html_export.md)
|
||||
- **confluence** with [its options](./Confluence_upload.md)
|
||||
|
||||
Available formats are __HTML__ and __Confluence__
|
||||
Available formats are **HTML** and **Confluence**
|
||||
|
||||
### Ignore
|
||||
|
||||
Set custom files and entire folders to ignore within your `/docs` folder. For files make sure to include the file extension in the name. For both files and folders, names are case-sensitive.
|
||||
|
||||
```json
|
||||
{
|
||||
"ignore": {
|
||||
"files": ["Work_In_Progress.md"],
|
||||
"folders": ["99_Not_Ready"]
|
||||
}
|
||||
"ignore": {
|
||||
"files": ["Work_In_Progress.md"],
|
||||
"folders": ["99_Not_Ready"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Timezone
|
||||
|
||||
If your server does not have a default timezone set in php.ini, it may return errors when it tries to generate the last modified date/time for docs. To fix these errors, specify a timezone in your config file. Valid options are available in the [PHP Manual](http://php.net/manual/en/timezones.php).
|
||||
|
||||
```json
|
||||
{
|
||||
"timezone": "America/Los_Angeles"
|
||||
"timezone": "America/Los_Angeles"
|
||||
}
|
||||
```
|
||||
|
||||
### Multi-language
|
||||
|
||||
Enables multi-language support which needs separate directories for each language in `docs/` folder.
|
||||
|
||||
```json
|
||||
{
|
||||
"languages": {"en": "English", "de": "German"}
|
||||
"languages": { "en": "English", "de": "German" }
|
||||
}
|
||||
```
|
||||
|
||||
Directory structure:
|
||||
|
||||
```
|
||||
├── docs/
|
||||
│ ├── _index.md
|
||||
@ -113,7 +122,7 @@ You can change the default language with the `language` option.
|
||||
|
||||
```json
|
||||
{
|
||||
"language": "fr"
|
||||
"language": "fr"
|
||||
}
|
||||
```
|
||||
|
||||
@ -124,31 +133,28 @@ A string that isn't found will fall back to english.
|
||||
|
||||
```json
|
||||
{
|
||||
"strings": {
|
||||
"fr": {
|
||||
"CodeBlocks_title": "Afficher le code",
|
||||
"CodeBlocks_hide": "Non",
|
||||
"CodeBlocks_below": "En Dessous",
|
||||
"CodeBlocks_inline": "A côté",
|
||||
"CodeBlocks_show": "Afficher le code",
|
||||
"Search_placeholder": "Rechercher...",
|
||||
"Link_previous": "Précédent",
|
||||
"Link_next": "Suivant",
|
||||
"Edit_on": "Editer sur :name:",
|
||||
"View_on_github": "Voir sur GitHub",
|
||||
"View_documentation": "Voir la Documentation"
|
||||
"strings": {
|
||||
"fr": {
|
||||
"CodeBlocks_show": "Afficher le code",
|
||||
"Search_placeholder": "Rechercher...",
|
||||
"Link_previous": "Précédent",
|
||||
"Link_next": "Suivant",
|
||||
"Edit_on": "Editer sur :name:",
|
||||
"View_on_github": "Voir sur GitHub",
|
||||
"View_documentation": "Voir la Documentation"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Processor
|
||||
|
||||
You can set the processor in the documentation or as an option to the command line. If you need it when running the server, you should add it to the configuration.
|
||||
|
||||
More information on how to create a Processor can be found [here](!For_Developers/Creating_a_Processor).
|
||||
|
||||
```json
|
||||
{
|
||||
"processor": "MyProcessor"
|
||||
"processor": "MyProcessor"
|
||||
}
|
||||
```
|
||||
|
@ -92,4 +92,3 @@ public function addGenerators()
|
||||
return ['custom_generator' => '\Todaymade\Daux\Extension\MyNewGenerator'];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -2,44 +2,51 @@ In its simplest form, a theme is an empty folder with a `config.json` file conta
|
||||
|
||||
After that, every setting is optional, but you can override everything if you'd like to.
|
||||
|
||||
> **Overriding styles**
|
||||
>
|
||||
> If you want to tweak a few styles, you can create a `style.css` file at the root of your documentation
|
||||
> directory and it will be included automatically. By doing this, you don't need to create a new theme.
|
||||
|
||||
## `config.json` options
|
||||
|
||||
Here is an example `config.json` file :
|
||||
|
||||
```json
|
||||
{
|
||||
"favicon": "<theme_url>img/favicon.png",
|
||||
"css": ["<theme_url>css/theme.min.css"],
|
||||
"js": [],
|
||||
"fonts": ["https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"],
|
||||
"variants": {
|
||||
"blue": {
|
||||
"favicon": "<theme_url>img/favicon-blue.png",
|
||||
"css": ["<theme_url>css/theme-blue.min.css"]
|
||||
},
|
||||
"green": {
|
||||
"favicon": "<theme_url>img/favicon-green.png",
|
||||
"css": ["<theme_url>css/theme-green.min.css"]
|
||||
"favicon": "<theme_url>img/favicon.png",
|
||||
"css": ["<theme_url>css/theme.min.css"],
|
||||
"js": [],
|
||||
"fonts": [
|
||||
"https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"
|
||||
],
|
||||
"variants": {
|
||||
"blue": {
|
||||
"favicon": "<theme_url>img/favicon-blue.png",
|
||||
"css": ["<theme_url>css/theme-blue.min.css"]
|
||||
},
|
||||
"green": {
|
||||
"favicon": "<theme_url>img/favicon-green.png",
|
||||
"css": ["<theme_url>css/theme-green.min.css"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
There are five options :
|
||||
|
||||
- __`favicon`__: The URL to your favicon
|
||||
- __`css`__: An array of CSS Stylesheets to add to the page
|
||||
- __`js`__: An array of JavaScript files to load
|
||||
- __`fonts`__: An array of Font sources, these are added as stylesheets
|
||||
- __`variants`__: An object containing sub-themes. Each sub theme, can provide the same configurations as the main theme (`favicon`, `css`, `js`, `fonts`)
|
||||
|
||||
- **`favicon`**: The URL to your favicon
|
||||
- **`css`**: An array of CSS Stylesheets to add to the page
|
||||
- **`js`**: An array of JavaScript files to load
|
||||
- **`fonts`**: An array of Font sources, these are added as stylesheets
|
||||
- **`variants`**: An object containing sub-themes. Each sub theme, can provide the same configurations as the main theme (`favicon`, `css`, `js`, `fonts`)
|
||||
|
||||
You will also notice this `<theme_url>` in the url.
|
||||
This is automatically substituted with the final url to the theme when generating the final page.
|
||||
|
||||
There are two possible substitutions :
|
||||
- __`<theme_url>`__: The url to the current theme
|
||||
- __`<base_url>`__: The url to the documentation root
|
||||
|
||||
- **`<theme_url>`**: The url to the current theme
|
||||
- **`<base_url>`**: The url to the documentation root
|
||||
|
||||
## Theme variants
|
||||
|
||||
@ -63,10 +70,10 @@ Change the `theme` option inside `html`
|
||||
|
||||
```json
|
||||
{
|
||||
"themes_directory": "/home/user/themes",
|
||||
"html": {
|
||||
"theme": "{theme}-{variant}"
|
||||
}
|
||||
"themes_directory": "/home/user/themes",
|
||||
"html": {
|
||||
"theme": "{theme}-{variant}"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -85,11 +92,12 @@ You can create a folder named `templates` in your theme, copy-paste the original
|
||||
You can even do it one template at a time if you wish to do only small changes.
|
||||
|
||||
By default, we have the following templates :
|
||||
- `content.php`: The content page.
|
||||
- `home.php`: The landing page.
|
||||
- `error.php`: The page to show when a page is not found or some other error happened.
|
||||
- `partials/navbar_content.php`: The content of the top navigation bar.
|
||||
- `partials/google_analytics.php`: The script to load Google Analytics.
|
||||
- `partials/piwik_analytics.php`: The script to load Piwik Analytics.
|
||||
- `layout/00_layout.php`: The master template, containing the `<html>` tag.
|
||||
- `layout/05_page.php`: The page layout, with left navigation.
|
||||
|
||||
- `content.php`: The content page.
|
||||
- `home.php`: The landing page.
|
||||
- `error.php`: The page to show when a page is not found or some other error happened.
|
||||
- `partials/navbar_content.php`: The content of the top navigation bar.
|
||||
- `partials/google_analytics.php`: The script to load Google Analytics.
|
||||
- `partials/piwik_analytics.php`: The script to load Piwik Analytics.
|
||||
- `layout/00_layout.php`: The master template, containing the `<html>` tag.
|
||||
- `layout/05_page.php`: The page layout, with left navigation.
|
||||
|
@ -13,37 +13,37 @@
|
||||
|
||||
#### For Authors
|
||||
|
||||
* [Auto Generated Navigation / Page sorting](01_Features/Navigation_and_Sorting.md)
|
||||
* [Internal documentation links](01_Features/Internal_links.md)
|
||||
* [CommonMark compliant](01_Features/CommonMark_compliant.md)
|
||||
* [Auto created homepage/landing page](01_Features/Landing_page.md)
|
||||
* [Multiple Output Formats](01_Features/Multiple_Output_Formats.md)
|
||||
* [Multiple Languages Support](01_Features/Multilanguage.md)
|
||||
* [No Build Step](01_Features/Live_mode.md)
|
||||
* [Static Output Generation](01_Features/Static_Site_Generation.md)
|
||||
* [Table of Contents](01_Features/Table_of_contents.md)
|
||||
- [Auto Generated Navigation / Page sorting](01_Features/Navigation_and_Sorting.md)
|
||||
- [Internal documentation links](01_Features/Internal_links.md)
|
||||
- [CommonMark compliant](01_Features/CommonMark_compliant.md)
|
||||
- [Auto created homepage/landing page](01_Features/Landing_page.md)
|
||||
- [Multiple Output Formats](01_Features/Multiple_Output_Formats.md)
|
||||
- [Multiple Languages Support](01_Features/Multilanguage.md)
|
||||
- [No Build Step](01_Features/Live_mode.md)
|
||||
- [Static Output Generation](01_Features/Static_Site_Generation.md)
|
||||
- [Table of Contents](01_Features/Table_of_contents.md)
|
||||
|
||||
</div>
|
||||
<div class="Row__third">
|
||||
|
||||
#### For Developers
|
||||
|
||||
* [Auto Syntax Highlighting](01_Features/Auto_Syntax_Highlight.md)
|
||||
* [Extend Daux.io with Processors](01_For_Developers/Creating_a_Processor.md)
|
||||
* Full access to the internal API to create new pages programatically
|
||||
* Work with pages metadata
|
||||
- [Auto Syntax Highlighting](01_Features/Auto_Syntax_Highlight.md)
|
||||
- [Extend Daux.io with Processors](01_For_Developers/Creating_a_Processor.md)
|
||||
- Full access to the internal API to create new pages programatically
|
||||
- Work with pages metadata
|
||||
|
||||
</div>
|
||||
<div class="Row__third">
|
||||
|
||||
#### For Marketing
|
||||
|
||||
* 100% Mobile Responsive
|
||||
* 4 Built-In Themes or roll your own
|
||||
* Functional, Flat Design Style
|
||||
* Optional code float layout
|
||||
* Shareable/Linkable SEO Friendly URLs
|
||||
* Supports Google Analytics and Piwik Analytics
|
||||
- 100% Mobile Responsive
|
||||
- 4 Built-In Themes or roll your own
|
||||
- Functional, Flat Design Style
|
||||
- Optional code float layout
|
||||
- Shareable/Linkable SEO Friendly URLs
|
||||
- Supports Google Analytics and Piwik Analytics
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -52,7 +52,7 @@
|
||||
|
||||
### Installation and usage
|
||||
|
||||
If you have __PHP__ and Composer installed
|
||||
If you have **PHP** and Composer installed
|
||||
|
||||
```bash
|
||||
composer global require daux/daux.io
|
||||
@ -61,7 +61,7 @@ composer global require daux/daux.io
|
||||
daux generate
|
||||
```
|
||||
|
||||
Or if you wish to use __Docker__
|
||||
Or if you wish to use **Docker**
|
||||
|
||||
```bash
|
||||
# Next to your `docs` folder, run
|
||||
@ -69,18 +69,3 @@ docker run --rm -it -w /build -v "$PWD":/build daux/daux.io daux generate
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
<!-- Google Code -->
|
||||
<script type="text/javascript">
|
||||
var google_conversion_id = 983836026;
|
||||
var google_custom_params = window.google_tag_params;
|
||||
var google_remarketing_only = true;
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
|
||||
</script>
|
||||
<noscript>
|
||||
<div style="display:inline;">
|
||||
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/983836026/?value=0&guid=ON&script=0"/>
|
||||
</div>
|
||||
</noscript>
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 81 KiB |
BIN
docs/app.png
BIN
docs/app.png
Binary file not shown.
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 100 KiB |
@ -21,13 +21,14 @@
|
||||
"repo": "dauxio/daux.io",
|
||||
"edit_on_github": "dauxio/daux.io/blob/master/docs",
|
||||
"twitter": ["onigoetz"],
|
||||
"google_analytics": "UA-3551397-7",
|
||||
"google_analytics": false,
|
||||
"plausible_domain": false,
|
||||
"links": {
|
||||
"Download": "https://github.com/dauxio/daux.io/archive/master.zip",
|
||||
"GitHub Repo": "https://github.com/dauxio/daux.io",
|
||||
"Help/Support/Bugs": "https://github.com/dauxio/daux.io/issues"
|
||||
"GitHub Repository": "https://github.com/dauxio/daux.io",
|
||||
"Help/Support/Bugs": "https://github.com/dauxio/daux.io/issues",
|
||||
"Packagist": "https://packagist.org/packages/daux/daux.io",
|
||||
"Docker Images": "https://hub.docker.com/r/daux/daux.io"
|
||||
},
|
||||
|
||||
"powered_by": "Powered by Daux.io"
|
||||
},
|
||||
"confluence": {
|
||||
|
16
global.json
16
global.json
@ -22,10 +22,6 @@
|
||||
|
||||
"strings": {
|
||||
"en": {
|
||||
"CodeBlocks_title": "Code blocks",
|
||||
"CodeBlocks_hide": "No",
|
||||
"CodeBlocks_below": "Below",
|
||||
"CodeBlocks_inline": "Inline",
|
||||
"CodeBlocks_show": "Show Code Blocks",
|
||||
"Search_placeholder": "Search...",
|
||||
"Search_one_result": "1 result",
|
||||
@ -44,10 +40,6 @@
|
||||
"Toggle_navigation": "Toggle navigation"
|
||||
},
|
||||
"fr": {
|
||||
"CodeBlocks_title": "Afficher le code",
|
||||
"CodeBlocks_hide": "Non",
|
||||
"CodeBlocks_below": "En Dessous",
|
||||
"CodeBlocks_inline": "A côté",
|
||||
"CodeBlocks_show": "Afficher le code",
|
||||
"Search_placeholder": "Rechercher...",
|
||||
"Search_one_result": "1 résultat",
|
||||
@ -65,10 +57,6 @@
|
||||
"Table_of_contents": "Table des matières"
|
||||
},
|
||||
"de": {
|
||||
"CodeBlocks_title": "Code-Blöcke",
|
||||
"CodeBlocks_hide": "Aus",
|
||||
"CodeBlocks_below": "Unterhalb",
|
||||
"CodeBlocks_inline": "Linear",
|
||||
"CodeBlocks_show": "Code-Blöcke anzeigen",
|
||||
"Search_placeholder": "Suchen...",
|
||||
"Search_one_result": "1 Ergebnis",
|
||||
@ -86,10 +74,6 @@
|
||||
"Table_of_contents": "Inhaltsverzeichnis"
|
||||
},
|
||||
"it": {
|
||||
"CodeBlocks_title": "Blocchi di codice",
|
||||
"CodeBlocks_hide": "No",
|
||||
"CodeBlocks_below": "Sotto",
|
||||
"CodeBlocks_inline": "In linea",
|
||||
"CodeBlocks_show": "Mostra blocchi di codice",
|
||||
"Search_one_result": "1 risultato",
|
||||
"Search_results": "!count risultati",
|
||||
|
@ -5,7 +5,7 @@ use ArrayObject;
|
||||
class BaseConfig extends ArrayObject
|
||||
{
|
||||
/**
|
||||
* Merge an array into the object
|
||||
* Merge an array into the object.
|
||||
*
|
||||
* @param array $newValues
|
||||
* @param bool $override
|
||||
@ -15,8 +15,9 @@ class BaseConfig extends ArrayObject
|
||||
foreach ($newValues as $key => $value) {
|
||||
// If the key doesn't exist yet,
|
||||
// we can simply set it.
|
||||
if (!array_key_exists($key, $this)) {
|
||||
if (!array_key_exists($key, (array) $this)) {
|
||||
$this[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -36,4 +37,19 @@ class BaseConfig extends ArrayObject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hasValue($key)
|
||||
{
|
||||
return array_key_exists($key, (array) $this);
|
||||
}
|
||||
|
||||
public function getValue($key)
|
||||
{
|
||||
return $this[$key];
|
||||
}
|
||||
|
||||
public function setValue($key, $value)
|
||||
{
|
||||
$this[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
<?php namespace Todaymade\Daux;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Daux;
|
||||
|
||||
class Cache
|
||||
{
|
||||
public static $printed = false;
|
||||
|
||||
static $printed = false;
|
||||
|
||||
public static function getDirectory()
|
||||
public static function getDirectory(): string
|
||||
{
|
||||
$dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "dauxio" . DIRECTORY_SEPARATOR;
|
||||
$dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'dauxio' . DIRECTORY_SEPARATOR;
|
||||
|
||||
if (!Cache::$printed) {
|
||||
Cache::$printed = true;
|
||||
@ -22,12 +20,8 @@ class Cache
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public static function put($key, $value)
|
||||
public static function put(string $key, string $value): void
|
||||
{
|
||||
Cache::ensureCacheDirectoryExists($path = Cache::path($key));
|
||||
file_put_contents($path, $value);
|
||||
@ -35,11 +29,8 @@ class Cache
|
||||
|
||||
/**
|
||||
* Create the file cache directory if necessary.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
protected static function ensureCacheDirectoryExists($path)
|
||||
protected static function ensureCacheDirectoryExists(string $path): void
|
||||
{
|
||||
$parent = dirname($path);
|
||||
|
||||
@ -50,11 +41,8 @@ class Cache
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function forget($key)
|
||||
public static function forget(string $key): bool
|
||||
{
|
||||
$path = Cache::path($key);
|
||||
|
||||
@ -68,10 +56,9 @@ class Cache
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($key)
|
||||
public static function get(string $key): ?string
|
||||
{
|
||||
$path = Cache::path($key);
|
||||
|
||||
@ -84,33 +71,30 @@ class Cache
|
||||
|
||||
/**
|
||||
* Get the full path for the given cache key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected static function path($key)
|
||||
protected static function path(string $key): string
|
||||
{
|
||||
$parts = array_slice(str_split($hash = sha1($key), 2), 0, 2);
|
||||
|
||||
return Cache::getDirectory() . '/' . implode('/', $parts) . '/' . $hash;
|
||||
}
|
||||
|
||||
public static function clear()
|
||||
public static function clear(): void
|
||||
{
|
||||
Cache::rrmdir(Cache::getDirectory());
|
||||
}
|
||||
|
||||
protected static function rrmdir($dir)
|
||||
protected static function rrmdir(string $dir): void
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
if ($object != "." && $object != "..") {
|
||||
if (is_dir($dir . "/" . $object)) {
|
||||
Cache::rrmdir($dir . "/" . $object);
|
||||
if ($object != '.' && $object != '..') {
|
||||
if (is_dir($dir . '/' . $object)) {
|
||||
Cache::rrmdir($dir . '/' . $object);
|
||||
} else {
|
||||
unlink($dir . "/" . $object);
|
||||
unlink($dir . '/' . $object);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
|
261
libs/Config.php
261
libs/Config.php
@ -1,88 +1,116 @@
|
||||
<?php namespace Todaymade\Daux;
|
||||
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Format\Confluence\Config as ConfluenceConfig;
|
||||
use Todaymade\Daux\Format\HTML\Config as HTMLConfig;
|
||||
use Todaymade\Daux\Format\HTML\Theme as Theme;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
|
||||
class Config extends BaseConfig
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return $this['title'];
|
||||
return $this->getValue('title');
|
||||
}
|
||||
|
||||
public function hasAuthor(): bool
|
||||
{
|
||||
return $this->hasValue('author');
|
||||
}
|
||||
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->getValue('author');
|
||||
}
|
||||
|
||||
public function hasTagline(): bool
|
||||
{
|
||||
return $this->hasValue('tagline');
|
||||
}
|
||||
|
||||
public function getTagline()
|
||||
{
|
||||
return $this->getValue('tagline');
|
||||
}
|
||||
|
||||
public function getCurrentPage()
|
||||
{
|
||||
return $this['current_page'];
|
||||
return $this->getValue('current_page');
|
||||
}
|
||||
|
||||
public function setCurrentPage(Content $entry)
|
||||
{
|
||||
$this['current_page'] = $entry;
|
||||
$this->setValue('current_page', $entry);
|
||||
}
|
||||
|
||||
public function getDocumentationDirectory()
|
||||
{
|
||||
return $this['docs_directory'];
|
||||
}
|
||||
|
||||
public function setDocumentationDirectory($documentationPath)
|
||||
{
|
||||
$this['docs_directory'] = $documentationPath;
|
||||
return $this->getValue('docs_directory');
|
||||
}
|
||||
|
||||
public function getThemesDirectory()
|
||||
{
|
||||
return $this['themes_directory'];
|
||||
}
|
||||
|
||||
public function setThemesDirectory($directory)
|
||||
{
|
||||
$this['themes_directory'] = $directory;
|
||||
}
|
||||
|
||||
public function setThemesPath($themePath)
|
||||
{
|
||||
$this['themes_path'] = $themePath;
|
||||
return $this->getValue('themes_directory');
|
||||
}
|
||||
|
||||
public function getThemesPath()
|
||||
{
|
||||
return $this['themes_path'];
|
||||
}
|
||||
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this['format'] = $format;
|
||||
return $this->getValue('themes_path');
|
||||
}
|
||||
|
||||
public function getFormat()
|
||||
{
|
||||
return $this['format'];
|
||||
return $this->getValue('format');
|
||||
}
|
||||
|
||||
public function hasTimezone()
|
||||
public function hasTimezone(): bool
|
||||
{
|
||||
return isset($this['timezone']);
|
||||
}
|
||||
|
||||
public function getTimezone()
|
||||
{
|
||||
return $this['timezone'];
|
||||
return $this->getValue('timezone');
|
||||
}
|
||||
|
||||
public function isMultilanguage()
|
||||
public function getTree()
|
||||
{
|
||||
return array_key_exists('languages', $this) && !empty($this['languages']);
|
||||
return $this->getValue('tree');
|
||||
}
|
||||
|
||||
public function setTree($tree)
|
||||
{
|
||||
$this->setValue('tree', $tree);
|
||||
}
|
||||
|
||||
public function isMultilanguage(): bool
|
||||
{
|
||||
return $this->hasValue('languages') && !empty($this->getValue('languages'));
|
||||
}
|
||||
|
||||
public function getLanguages(): array
|
||||
{
|
||||
return $this->getValue('languages');
|
||||
}
|
||||
|
||||
public function getLanguage(): string
|
||||
{
|
||||
return $this->getValue('language');
|
||||
}
|
||||
|
||||
public function getMode()
|
||||
{
|
||||
return $this->getValue('mode');
|
||||
}
|
||||
|
||||
public function isLive()
|
||||
{
|
||||
return $this['mode'] == Daux::LIVE_MODE;
|
||||
return $this->getValue('mode') == Daux::LIVE_MODE;
|
||||
}
|
||||
|
||||
public function isStatic()
|
||||
{
|
||||
return $this['mode'] == Daux::STATIC_MODE;
|
||||
return $this->getValue('mode') == Daux::STATIC_MODE;
|
||||
}
|
||||
|
||||
public function shouldInheritIndex()
|
||||
@ -90,41 +118,52 @@ class Config extends BaseConfig
|
||||
// As the global configuration is always present, we
|
||||
// need to test for the existence of the legacy value
|
||||
// first. Then use the current value.
|
||||
if (array_key_exists('live', $this) && array_key_exists('inherit_index', $this['live'])) {
|
||||
if ($this->hasValue('live') && array_key_exists('inherit_index', $this['live'])) {
|
||||
return $this['live']['inherit_index'];
|
||||
}
|
||||
|
||||
return $this['html']['inherit_index'];
|
||||
}
|
||||
|
||||
public function setConfigurationOverrideFile($override_file)
|
||||
public function getIndexKey()
|
||||
{
|
||||
$this['override_file'] = $override_file;
|
||||
return $this->getValue('mode') == Daux::STATIC_MODE ? 'index.html' : 'index';
|
||||
}
|
||||
|
||||
public function getConfigurationOverrideFile()
|
||||
public function getProcessor()
|
||||
{
|
||||
if (array_key_exists('override_file', $this)) {
|
||||
return $this['override_file'];
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->getValue('processor');
|
||||
}
|
||||
|
||||
public function getConfluenceConfiguration()
|
||||
public function getConfluenceConfiguration(): ConfluenceConfig
|
||||
{
|
||||
return $this['confluence'];
|
||||
return new ConfluenceConfig($this->hasValue('confluence') ? $this->getValue('confluence') : []);
|
||||
}
|
||||
|
||||
public function getHTML()
|
||||
public function getHTML(): HTMLConfig
|
||||
{
|
||||
return new HTMLConfig($this['html']);
|
||||
return new HTMLConfig($this->hasValue('html') ? $this->getValue('html') : []);
|
||||
}
|
||||
|
||||
public function getTheme(): ?Theme
|
||||
{
|
||||
return $this->hasValue('theme') ? new Theme($this->getValue('theme')) : null;
|
||||
}
|
||||
|
||||
public function getValidContentExtensions()
|
||||
{
|
||||
return $this->getValue('valid_content_extensions');
|
||||
}
|
||||
|
||||
public function setValidContentExtensions(array $value)
|
||||
{
|
||||
$this->setValue('valid_content_extensions', $value);
|
||||
}
|
||||
|
||||
public function canCache()
|
||||
{
|
||||
if (array_key_exists('cache', $this)) {
|
||||
return $this['cache'];
|
||||
if ($this->hasValue('cache')) {
|
||||
return $this->getValue('cache');
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -139,4 +178,128 @@ class Config extends BaseConfig
|
||||
|
||||
return sha1(json_encode($cloned));
|
||||
}
|
||||
|
||||
public function hasTranslationKey($language, $key): bool
|
||||
{
|
||||
return array_key_exists($language, $this['strings']) && array_key_exists($key, $this['strings'][$language]);
|
||||
}
|
||||
|
||||
public function getTranslationKey($language, $key)
|
||||
{
|
||||
return $this['strings'][$language][$key];
|
||||
}
|
||||
|
||||
public function hasImage(): bool
|
||||
{
|
||||
return $this->hasValue('image') && !empty($this->getValue('image'));
|
||||
}
|
||||
|
||||
public function getImage()
|
||||
{
|
||||
return $this->getValue('image');
|
||||
}
|
||||
|
||||
public function setImage($value)
|
||||
{
|
||||
$this->setValue('image', $value);
|
||||
}
|
||||
|
||||
public function getLocalBase()
|
||||
{
|
||||
return $this->getValue('local_base');
|
||||
}
|
||||
|
||||
public function getTemplates()
|
||||
{
|
||||
return $this->getValue('templates');
|
||||
}
|
||||
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return $this->getValue('base_url');
|
||||
}
|
||||
|
||||
public function getBasePage()
|
||||
{
|
||||
if ($this->isLive()) {
|
||||
$value = '//' . $this->getBaseUrl();
|
||||
if (!$this['live']['clean_urls']) {
|
||||
$value .= 'index.php/';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $this->getBaseUrl();
|
||||
}
|
||||
|
||||
public function hasEntryPage(): bool
|
||||
{
|
||||
return $this->hasValue('entry_page') && !empty($this->getValue('entry_page'));
|
||||
}
|
||||
|
||||
public function getEntryPage()
|
||||
{
|
||||
return $this->getValue('entry_page');
|
||||
}
|
||||
|
||||
public function setEntryPage($value)
|
||||
{
|
||||
$this->setValue('entry_page', $value);
|
||||
}
|
||||
|
||||
public function hasRequest(): bool
|
||||
{
|
||||
return $this->hasValue('request') && !empty($this->getValue('request'));
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->getValue('request');
|
||||
}
|
||||
|
||||
public function setRequest($value)
|
||||
{
|
||||
$this->setValue('request', $value);
|
||||
}
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
return $this->getValue('index');
|
||||
}
|
||||
|
||||
public function setIndex($value)
|
||||
{
|
||||
$this->setValue('index', $value);
|
||||
}
|
||||
|
||||
public function hasProcessorInstance()
|
||||
{
|
||||
return $this->hasValue('processor_instance');
|
||||
}
|
||||
|
||||
public function getProcessorInstance()
|
||||
{
|
||||
return $this->getValue('processor_instance');
|
||||
}
|
||||
|
||||
public function setProcessorInstance($value)
|
||||
{
|
||||
$this->setValue('processor_instance', $value);
|
||||
}
|
||||
|
||||
public function getIgnore()
|
||||
{
|
||||
return $this->getValue('ignore');
|
||||
}
|
||||
|
||||
public function hasHost()
|
||||
{
|
||||
return $this->hasValue('host');
|
||||
}
|
||||
|
||||
public function getHost()
|
||||
{
|
||||
return $this->getValue('host');
|
||||
}
|
||||
}
|
||||
|
327
libs/ConfigBuilder.php
Normal file
327
libs/ConfigBuilder.php
Normal file
@ -0,0 +1,327 @@
|
||||
<?php namespace Todaymade\Daux;
|
||||
|
||||
class ConfigBuilder
|
||||
{
|
||||
/** @var Config */
|
||||
private $config;
|
||||
|
||||
/** @var array */
|
||||
private $overrideValues = [];
|
||||
|
||||
private $configuration_override_file;
|
||||
|
||||
private function __construct(string $mode)
|
||||
{
|
||||
$this->config = new Config();
|
||||
$this->config['mode'] = $mode;
|
||||
$this->config['local_base'] = dirname(__DIR__);
|
||||
}
|
||||
|
||||
public static function fromFile($file): Config
|
||||
{
|
||||
return unserialize(file_get_contents($file));
|
||||
}
|
||||
|
||||
public static function withMode($mode = Daux::STATIC_MODE): ConfigBuilder
|
||||
{
|
||||
$builder = new ConfigBuilder($mode);
|
||||
$builder->loadBaseConfiguration();
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function with(array $values): ConfigBuilder
|
||||
{
|
||||
$this->config->merge($values);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setValue(Config $array, $key, $value)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return $array = $value;
|
||||
}
|
||||
$keys = explode('.', $key);
|
||||
while (count($keys) > 1) {
|
||||
$key = array_shift($keys);
|
||||
if (!isset($array[$key]) || !is_array($array[$key])) {
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
$array[array_shift($keys)] = $value;
|
||||
}
|
||||
|
||||
public function withValues(array $values): ConfigBuilder
|
||||
{
|
||||
$this->overrideValues = $values;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDocumentationDirectory($dir): ConfigBuilder
|
||||
{
|
||||
$this->config['docs_directory'] = $dir;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withValidContentExtensions(array $value): ConfigBuilder
|
||||
{
|
||||
$this->config['valid_content_extensions'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withThemesPath($themePath): ConfigBuilder
|
||||
{
|
||||
$this->config['themes_path'] = $themePath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withThemesDirectory($directory): ConfigBuilder
|
||||
{
|
||||
$this->config['themes_directory'] = $directory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withCache(bool $value): ConfigBuilder
|
||||
{
|
||||
$this->config['cache'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withFormat($format): ConfigBuilder
|
||||
{
|
||||
$this->config['format'] = $format;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withConfigurationOverride($file): ConfigBuilder
|
||||
{
|
||||
$this->configuration_override_file = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withProcessor($value): ConfigBuilder
|
||||
{
|
||||
$this->config['processor'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withConfluenceDelete($value): ConfigBuilder
|
||||
{
|
||||
$this->config['confluence']['delete'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build(): Config
|
||||
{
|
||||
$this->initializeConfiguration();
|
||||
|
||||
foreach ($this->overrideValues as $value) {
|
||||
$this->setValue($this->config, $value[0], $value[1]);
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
private function resolveThemeVariant()
|
||||
{
|
||||
$theme = $this->config->getHTML()->getTheme();
|
||||
$themesPath = $this->config->getThemesPath() . DIRECTORY_SEPARATOR;
|
||||
|
||||
// If theme directory exists, we're good with that
|
||||
if (is_dir(realpath(($themesPath . $theme)))) {
|
||||
return [$theme, ''];
|
||||
}
|
||||
|
||||
$themePieces = explode('-', $theme);
|
||||
$variant = '';
|
||||
|
||||
// Do we have a variant or only a theme ?
|
||||
if (count($themePieces) > 1) {
|
||||
$variant = array_pop($themePieces);
|
||||
$theme = implode('-', $themePieces);
|
||||
}
|
||||
|
||||
if (!is_dir(realpath($themesPath . $theme))) {
|
||||
throw new \RuntimeException("Theme '{$theme}' not found");
|
||||
}
|
||||
|
||||
return [$theme, $variant];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $override_file
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function initializeConfiguration()
|
||||
{
|
||||
// Validate and set theme path
|
||||
$docs_path = $this->normalizeDocumentationPath($this->config->getDocumentationDirectory());
|
||||
$this->config['docs_directory'] = $docs_path;
|
||||
|
||||
// Read documentation overrides
|
||||
$this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
||||
|
||||
// Read command line overrides
|
||||
$override_file = $this->getConfigurationOverride($this->configuration_override_file);
|
||||
if ($override_file !== null) {
|
||||
$this->loadConfiguration($override_file);
|
||||
}
|
||||
|
||||
// Validate and set theme path
|
||||
$this->withThemesPath($this->normalizeThemePath($this->config->getThemesDirectory()));
|
||||
|
||||
// Resolve variant once
|
||||
$theme = $this->resolveThemeVariant();
|
||||
$this->config['html']['theme'] = $theme[0];
|
||||
$this->config['html']['theme-variant'] = $theme[1];
|
||||
|
||||
// Set a valid default timezone
|
||||
if ($this->config->hasTimezone()) {
|
||||
date_default_timezone_set($this->config->getTimezone());
|
||||
} elseif (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('GMT');
|
||||
}
|
||||
|
||||
// Text search would be too slow on live server
|
||||
if ($this->config->isLive()) {
|
||||
$this->config['html']['search'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeThemePath($path)
|
||||
{
|
||||
$validPath = $this->findLocation($path, $this->config->getLocalBase(), 'dir');
|
||||
|
||||
if (!$validPath) {
|
||||
throw new Exception('The Themes directory does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
return $validPath;
|
||||
}
|
||||
|
||||
private function normalizeDocumentationPath($path)
|
||||
{
|
||||
$validPath = $this->findLocation($path, $this->config->getLocalBase(), 'dir');
|
||||
|
||||
if (!$validPath) {
|
||||
throw new Exception('The Docs directory does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
return $validPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and validate the global configuration.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function loadBaseConfiguration()
|
||||
{
|
||||
// Set the default configuration
|
||||
$this->config->merge([
|
||||
'docs_directory' => 'docs',
|
||||
'valid_content_extensions' => ['md', 'markdown'],
|
||||
|
||||
//Paths and tree
|
||||
'templates' => 'templates',
|
||||
|
||||
'base_url' => '',
|
||||
]);
|
||||
|
||||
// Load the global configuration
|
||||
$this->loadConfiguration($this->config->getLocalBase() . DIRECTORY_SEPARATOR . 'global.json', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $config_file
|
||||
* @param bool $optional
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function loadConfiguration($config_file, $optional = true)
|
||||
{
|
||||
if (!file_exists($config_file)) {
|
||||
if ($optional) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception('The configuration file is missing. Check path : ' . $config_file);
|
||||
}
|
||||
|
||||
$config = json_decode(file_get_contents($config_file), true);
|
||||
if (!isset($config)) {
|
||||
throw new Exception('The configuration file "' . $config_file . '" is corrupt. Is your JSON well-formed ?');
|
||||
}
|
||||
$this->config->merge($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file requested for configuration overrides.
|
||||
*
|
||||
* @param null|string $path
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return null|string the path to a file to load for configuration overrides
|
||||
*/
|
||||
private function getConfigurationOverride($path)
|
||||
{
|
||||
$validPath = $this->findLocation($path, $this->config->getLocalBase(), 'file');
|
||||
|
||||
if ($validPath === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$validPath) {
|
||||
throw new Exception('The configuration override file does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
return $validPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $path
|
||||
* @param string $basedir
|
||||
* @param string $type
|
||||
*
|
||||
* @return null|false|string
|
||||
*/
|
||||
private function findLocation($path, $basedir, $type)
|
||||
{
|
||||
// If Path is explicitly null, it's useless to go further
|
||||
if ($path === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// VFS, used only in tests
|
||||
if (substr($path, 0, 6) == 'vfs://') {
|
||||
return $path;
|
||||
}
|
||||
|
||||
// Check if it's relative to the current directory or an absolute path
|
||||
if (DauxHelper::is($path, $type)) {
|
||||
return DauxHelper::getAbsolutePath($path);
|
||||
}
|
||||
|
||||
// Check if it exists relative to Daux's root
|
||||
$newPath = $basedir . DIRECTORY_SEPARATOR . $path;
|
||||
if (DauxHelper::is($newPath, $type)) {
|
||||
return $newPath;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -12,11 +12,11 @@ class Application extends SymfonyApplication
|
||||
$this->add(new Serve());
|
||||
$this->add(new ClearCache());
|
||||
|
||||
$app_name = "daux/daux.io";
|
||||
$app_name = 'daux/daux.io';
|
||||
|
||||
$up = '..' . DIRECTORY_SEPARATOR;
|
||||
$composer = __DIR__ . DIRECTORY_SEPARATOR . $up . $up . $up . $up . $up . 'composer.lock';
|
||||
$version = "unknown";
|
||||
$version = 'unknown';
|
||||
|
||||
if (file_exists($composer)) {
|
||||
$app = json_decode(file_get_contents($composer));
|
||||
|
@ -16,8 +16,10 @@ class ClearCache extends SymfonyCommand
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln("Clearing cache at '" . Cache::getDirectory() ."'");
|
||||
$output->writeln("Clearing cache at '" . Cache::getDirectory() . "'");
|
||||
Cache::clear();
|
||||
$output->writeln("<info>Cache cleared</info>");
|
||||
$output->writeln('<info>Cache cleared</info>');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\ConfigBuilder;
|
||||
use Todaymade\Daux\Daux;
|
||||
|
||||
class DauxCommand extends SymfonyCommand
|
||||
@ -12,78 +13,55 @@ class DauxCommand extends SymfonyCommand
|
||||
{
|
||||
$this
|
||||
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
||||
->addOption('value', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Set different configuration values')
|
||||
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
||||
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
|
||||
->addOption('no-cache', null, InputOption::VALUE_NONE, 'Disable Cache');
|
||||
|
||||
// HTML Format only
|
||||
$this->addOption('themes', 't', InputOption::VALUE_REQUIRED, 'Set a different themes directory');
|
||||
->addOption('no-cache', null, InputOption::VALUE_NONE, 'Disable Cache')
|
||||
->addOption('themes', 't', InputOption::VALUE_REQUIRED, 'Set a different themes directory (Used by HTML format only)')
|
||||
->addOption('value', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Set different configuration values');
|
||||
}
|
||||
|
||||
private function setValue(&$array, $key, $value)
|
||||
protected function prepareConfig($mode, InputInterface $input, OutputInterface $output): ConfigBuilder
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return $array = $value;
|
||||
}
|
||||
$keys = explode('.', $key);
|
||||
while (count($keys) > 1) {
|
||||
$key = array_shift($keys);
|
||||
if (!isset($array[$key]) || !is_array($array[$key])) {
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
$array[array_shift($keys)] = $value;
|
||||
return $array;
|
||||
}
|
||||
$builder = ConfigBuilder::withMode($mode);
|
||||
|
||||
private function applyConfiguration(array $options, Daux $daux)
|
||||
{
|
||||
$values = array_map(
|
||||
function($value) {
|
||||
return array_map("trim", explode('=', $value));
|
||||
},
|
||||
$options
|
||||
);
|
||||
|
||||
foreach ($values as $value) {
|
||||
$this->setValue($daux->options, $value[0], $value[1]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function prepareDaux(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$daux = new Daux(Daux::STATIC_MODE, $output);
|
||||
|
||||
// Set the format if requested
|
||||
if ($input->hasOption('format') && $input->getOption('format')) {
|
||||
$daux->getParams()->setFormat($input->getOption('format'));
|
||||
if ($input->getOption('configuration')) {
|
||||
$builder->withConfigurationOverride($input->getOption('configuration'));
|
||||
}
|
||||
|
||||
// Set the source directory
|
||||
if ($input->getOption('source')) {
|
||||
$daux->getParams()->setDocumentationDirectory($input->getOption('source'));
|
||||
$builder->withDocumentationDirectory($input->getOption('source'));
|
||||
}
|
||||
|
||||
if ($input->getOption('themes')) {
|
||||
$daux->getParams()->setThemesDirectory($input->getOption('themes'));
|
||||
}
|
||||
|
||||
$daux->initializeConfiguration($input->getOption('configuration'));
|
||||
|
||||
if ($input->hasOption('delete') && $input->getOption('delete')) {
|
||||
$daux->getParams()['confluence']['delete'] = true;
|
||||
}
|
||||
|
||||
if ($input->hasOption('value')) {
|
||||
$this->applyConfiguration($input->getOption('value'), $daux);
|
||||
if ($input->getOption('processor')) {
|
||||
$builder->withProcessor($input->getOption('processor'));
|
||||
}
|
||||
|
||||
if ($input->getOption('no-cache')) {
|
||||
$daux->getParams()['cache'] = false;
|
||||
$builder->withCache(false);
|
||||
}
|
||||
|
||||
return $daux;
|
||||
if ($input->getOption('themes')) {
|
||||
$builder->withThemesDirectory($input->getOption('themes'));
|
||||
}
|
||||
|
||||
if ($input->hasOption('value')) {
|
||||
$values = array_map(
|
||||
function ($value) {
|
||||
return array_map('trim', explode('=', $value));
|
||||
},
|
||||
$input->getOption('value')
|
||||
);
|
||||
$builder->withValues($values);
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
protected function prepareProcessor(Daux $daux, $width)
|
||||
{
|
||||
$class = $daux->getProcessorClass();
|
||||
if (!empty($class)) {
|
||||
$daux->setProcessor(new $class($daux, $daux->getOutput(), $width));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Terminal;
|
||||
use Todaymade\Daux\ConfigBuilder;
|
||||
use Todaymade\Daux\Daux;
|
||||
|
||||
class Generate extends DauxCommand
|
||||
@ -25,8 +26,23 @@ class Generate extends DauxCommand
|
||||
// Confluence format only
|
||||
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)')
|
||||
|
||||
->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static')
|
||||
->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search');
|
||||
->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static');
|
||||
}
|
||||
|
||||
protected function prepareConfig($mode, InputInterface $input, OutputInterface $output): ConfigBuilder
|
||||
{
|
||||
$builder = parent::prepareConfig($mode, $input, $output);
|
||||
|
||||
// Set the format if requested
|
||||
if ($input->hasOption('format') && $input->getOption('format')) {
|
||||
$builder->withFormat($input->getOption('format'));
|
||||
}
|
||||
|
||||
if ($input->hasOption('delete') && $input->getOption('delete')) {
|
||||
$builder->withConfluenceDelete(true);
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
@ -42,29 +58,20 @@ class Generate extends DauxCommand
|
||||
$input = new ArgvInput($argv, $this->getDefinition());
|
||||
}
|
||||
|
||||
$daux = $this->prepareDaux($input, $output);
|
||||
$builder = $this->prepareConfig(Daux::STATIC_MODE, $input, $output);
|
||||
$daux = new Daux($builder->build(), $output);
|
||||
|
||||
$width = (new Terminal)->getWidth();
|
||||
$width = (new Terminal())->getWidth();
|
||||
|
||||
// Instiantiate the processor if one is defined
|
||||
$this->prepareProcessor($daux, $input, $output, $width);
|
||||
$this->prepareProcessor($daux, $width);
|
||||
|
||||
// Generate the tree
|
||||
$daux->generateTree();
|
||||
|
||||
// Generate the documentation
|
||||
$daux->getGenerator()->generateAll($input, $output, $width);
|
||||
}
|
||||
|
||||
protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width)
|
||||
{
|
||||
if ($input->getOption('processor')) {
|
||||
$daux->getParams()['processor'] = $input->getOption('processor');
|
||||
}
|
||||
|
||||
$class = $daux->getProcessorClass();
|
||||
if (!empty($class)) {
|
||||
$daux->setProcessor(new $class($daux, $output, $width));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ use Todaymade\Daux\Daux;
|
||||
|
||||
trait RunAction
|
||||
{
|
||||
protected function getLength($content) {
|
||||
protected function getLength($content)
|
||||
{
|
||||
return function_exists('mb_strlen') ? mb_strlen($content) : strlen($content);
|
||||
}
|
||||
|
||||
@ -25,6 +26,7 @@ trait RunAction
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
$this->status($padding, '[ <fg=red>FAIL</fg=red> ]');
|
||||
|
||||
throw $e;
|
||||
}
|
||||
$this->status($padding, '[ <fg=green>OK</fg=green> ]');
|
||||
|
@ -1,13 +1,11 @@
|
||||
<?php namespace Todaymade\Daux\Console;
|
||||
|
||||
use Exception;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Terminal;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\ProcessUtils;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\Server\Server;
|
||||
|
||||
class Serve extends DauxCommand
|
||||
{
|
||||
@ -19,8 +17,6 @@ class Serve extends DauxCommand
|
||||
->setName('serve')
|
||||
->setDescription('Serve documentation')
|
||||
|
||||
// Serve the current documentation
|
||||
->addOption('serve', null, InputOption::VALUE_NONE, 'Serve the current directory')
|
||||
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The host to serve on', 'localhost')
|
||||
->addOption('port', null, InputOption::VALUE_REQUIRED, 'The port to serve on', 8085);
|
||||
}
|
||||
@ -30,23 +26,44 @@ class Serve extends DauxCommand
|
||||
$host = $input->getOption('host');
|
||||
$port = $input->getOption('port');
|
||||
|
||||
$daux = $this->prepareDaux($input, $output);
|
||||
$builder = $this->prepareConfig(Daux::LIVE_MODE, $input, $output);
|
||||
|
||||
// Daux can only serve HTML
|
||||
$daux->getParams()->setFormat('html');
|
||||
$builder->withFormat('html');
|
||||
|
||||
$daux = new Daux($builder->build(), $output);
|
||||
|
||||
$width = (new Terminal())->getWidth();
|
||||
|
||||
// Instiantiate the processor if one is defined
|
||||
$this->prepareProcessor($daux, $width);
|
||||
|
||||
// Write the current configuration to a file to read it from the other serving side
|
||||
$file = tmpfile();
|
||||
|
||||
if ($file === false) {
|
||||
$output->writeln('<fg=red>Failed to create temporary file for configuration</fg=red>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$path = stream_get_meta_data($file)['uri'];
|
||||
fwrite($file, serialize($daux->getConfig()));
|
||||
|
||||
chdir(__DIR__ . '/../../');
|
||||
|
||||
putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory());
|
||||
putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath());
|
||||
putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile());
|
||||
putenv('DAUX_CONFIG=' . $path);
|
||||
putenv('DAUX_VERBOSITY=' . $output->getVerbosity());
|
||||
putenv('DAUX_EXTENSION=' . DAUX_EXTENSION);
|
||||
|
||||
$base = escapeshellarg(__DIR__ . '/../../');
|
||||
$binary = escapeshellarg((new PhpExecutableFinder)->find(false));
|
||||
$binary = escapeshellarg((new PhpExecutableFinder())->find(false));
|
||||
|
||||
echo "Daux development server started on http://{$host}:{$port}/\n";
|
||||
|
||||
passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
|
||||
fclose($file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ interface ContentType
|
||||
public function __construct(Config $config);
|
||||
|
||||
/**
|
||||
* Get the file extensions supported by this Content Type
|
||||
* Get the file extensions supported by this Content Type.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
@ -17,6 +17,7 @@ interface ContentType
|
||||
/**
|
||||
* @param string $raw The raw text to render
|
||||
* @param Content $node The original node we are converting
|
||||
*
|
||||
* @return string The generated output
|
||||
*/
|
||||
public function convert($raw, Content $node);
|
||||
|
@ -18,7 +18,7 @@ class ContentTypeHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all valid content file extensions
|
||||
* Get all valid content file extensions.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
@ -33,9 +33,8 @@ class ContentTypeHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ContentType able to handle this node
|
||||
* Get the ContentType able to handle this node.
|
||||
*
|
||||
* @param Content $node
|
||||
* @return ContentType
|
||||
*/
|
||||
public function getType(Content $node)
|
||||
|
@ -1,22 +1,25 @@
|
||||
<?php namespace Todaymade\Daux\ContentTypes\Markdown;
|
||||
|
||||
use League\CommonMark\DocParser;
|
||||
use League\CommonMark\Environment;
|
||||
use League\CommonMark\HtmlRenderer;
|
||||
use League\CommonMark\Extension\Autolink\AutolinkExtension;
|
||||
use League\CommonMark\Extension\SmartPunct\SmartPunctExtension;
|
||||
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
|
||||
use League\CommonMark\Extension\Table\TableExtension;
|
||||
use League\CommonMark\Inline\Element as InlineElement;
|
||||
use Todaymade\Daux\Config;
|
||||
use Webuni\CommonMark\TableExtension\TableExtension;
|
||||
|
||||
class CommonMarkConverter extends \League\CommonMark\CommonMarkConverter
|
||||
{
|
||||
/**
|
||||
* Create a new commonmark converter instance.
|
||||
*
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
$environment = Environment::createCommonMarkEnvironment();
|
||||
$environment->mergeConfig($config);
|
||||
$environment->addExtension(new AutolinkExtension());
|
||||
$environment->addExtension(new SmartPunctExtension());
|
||||
$environment->addExtension(new StrikethroughExtension());
|
||||
$environment->addExtension(new TableExtension());
|
||||
|
||||
// Table of Contents
|
||||
@ -24,12 +27,11 @@ class CommonMarkConverter extends \League\CommonMark\CommonMarkConverter
|
||||
|
||||
$this->extendEnvironment($environment, $config['daux']);
|
||||
|
||||
if (array_key_exists('processor_instance', $config['daux'])) {
|
||||
$config['daux']['processor_instance']->extendCommonMarkEnvironment($environment);
|
||||
if ($config['daux']->hasProcessorInstance()) {
|
||||
$config['daux']->getProcessorInstance()->extendCommonMarkEnvironment($environment);
|
||||
}
|
||||
|
||||
$this->docParser = new DocParser($environment);
|
||||
$this->htmlRenderer = new HtmlRenderer($environment);
|
||||
parent::__construct($config, $environment);
|
||||
}
|
||||
|
||||
protected function getLinkRenderer(Environment $environment)
|
||||
@ -39,6 +41,6 @@ class CommonMarkConverter extends \League\CommonMark\CommonMarkConverter
|
||||
|
||||
protected function extendEnvironment(Environment $environment, Config $config)
|
||||
{
|
||||
$environment->addInlineRenderer('Link', $this->getLinkRenderer($environment));
|
||||
$environment->addInlineRenderer(InlineElement\Link::class, $this->getLinkRenderer($environment));
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,25 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType
|
||||
protected $config;
|
||||
|
||||
/** @var CommonMarkConverter */
|
||||
protected $converter;
|
||||
private $converter;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
||||
}
|
||||
|
||||
protected function createConverter()
|
||||
{
|
||||
return new CommonMarkConverter(['daux' => $this->config]);
|
||||
}
|
||||
|
||||
protected function getConverter()
|
||||
{
|
||||
if (!$this->converter) {
|
||||
$this->converter = $this->createConverter();
|
||||
}
|
||||
|
||||
return $this->converter;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,28 +43,32 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType
|
||||
|
||||
protected function doConversion($raw)
|
||||
{
|
||||
Daux::writeln("Running conversion", OutputInterface::VERBOSITY_VERBOSE);
|
||||
return $this->converter->convertToHtml($raw);
|
||||
Daux::writeln('Running conversion', OutputInterface::VERBOSITY_VERBOSE);
|
||||
|
||||
return $this->getConverter()->convertToHtml($raw);
|
||||
}
|
||||
|
||||
public function convert($raw, Content $node)
|
||||
{
|
||||
$this->config->setCurrentPage($node);
|
||||
|
||||
if (!$this->config->canCache()) {
|
||||
return $this->doConversion($raw);
|
||||
}
|
||||
$can_cache = $this->config->canCache();
|
||||
|
||||
// TODO :: add daux version to cache key
|
||||
$cacheKey = $this->config->getCacheKey() . sha1($raw);
|
||||
|
||||
$payload = Cache::get($cacheKey);
|
||||
|
||||
if ($payload) {
|
||||
Daux::writeln("Using cached version", OutputInterface::VERBOSITY_VERBOSE);
|
||||
} else {
|
||||
Daux::writeln("Not found in the cache, generating...", OutputInterface::VERBOSITY_VERBOSE);
|
||||
if ($can_cache && $payload) {
|
||||
Daux::writeln('Using cached version', OutputInterface::VERBOSITY_VERBOSE);
|
||||
}
|
||||
|
||||
if (!$can_cache || !$payload) {
|
||||
Daux::writeln($can_cache ? 'Not found in the cache, generating...' : 'Cache disabled, generating...', OutputInterface::VERBOSITY_VERBOSE);
|
||||
$payload = $this->doConversion($raw);
|
||||
}
|
||||
|
||||
if ($can_cache) {
|
||||
Cache::put($cacheKey, $payload);
|
||||
}
|
||||
|
||||
|
@ -4,102 +4,58 @@ use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
use League\CommonMark\Inline\Element\AbstractInline;
|
||||
use League\CommonMark\Inline\Element\Link;
|
||||
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
|
||||
use League\CommonMark\Util\ConfigurationAwareInterface;
|
||||
use League\CommonMark\Util\ConfigurationInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
|
||||
class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $daux;
|
||||
|
||||
/**
|
||||
* @var \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
public function __construct($daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return Entry
|
||||
* @throws LinkNotFoundException
|
||||
*/
|
||||
protected function resolveInternalFile($url)
|
||||
{
|
||||
$triedAbsolute = false;
|
||||
|
||||
// Legacy absolute paths could start with
|
||||
// "!" In this case we will try to find
|
||||
// the file starting at the root
|
||||
if ($url[0] == '!' || $url[0] == '/') {
|
||||
$url = ltrim($url, '!/');
|
||||
|
||||
if ($file = DauxHelper::getFile($this->daux['tree'], $url)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
$triedAbsolute = true;
|
||||
}
|
||||
|
||||
// Seems it's not an absolute path or not found,
|
||||
// so we'll continue with the current folder
|
||||
if ($file = DauxHelper::getFile($this->daux->getCurrentPage()->getParent(), $url)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
// If we didn't already try it, we'll
|
||||
// do a pass starting at the root
|
||||
if (!$triedAbsolute && $file = DauxHelper::getFile($this->daux['tree'], $url)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
throw new LinkNotFoundException("Could not locate file '$url'");
|
||||
}
|
||||
|
||||
protected function isValidUrl($url)
|
||||
{
|
||||
return !empty($url) && $url[0] != '#';
|
||||
}
|
||||
|
||||
protected function isExternalUrl($url)
|
||||
{
|
||||
return preg_match('#^(?:[a-z]+:)?//|^mailto:#', $url);
|
||||
$this->parent = new \League\CommonMark\Inline\Renderer\LinkRenderer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractInline|Link $inline
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @return HtmlElement
|
||||
*
|
||||
* @throws LinkNotFoundException
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
// This can't be in the method type as
|
||||
// the method is an abstract and should
|
||||
// have the same interface
|
||||
if (!$inline instanceof Link) {
|
||||
throw new \RuntimeException(
|
||||
'Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ .
|
||||
" the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" .
|
||||
get_class($inline) . "' was provided"
|
||||
);
|
||||
if (!($inline instanceof Link)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
$element = parent::render($inline, $htmlRenderer);
|
||||
$element = $this->parent->render($inline, $htmlRenderer);
|
||||
|
||||
$url = $inline->getUrl();
|
||||
|
||||
// empty urls and anchors should
|
||||
// not go through the url resolver
|
||||
if (!$this->isValidUrl($url)) {
|
||||
if (!DauxHelper::isValidUrl($url)) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
// Absolute urls, shouldn't either
|
||||
if ($this->isExternalUrl($url)) {
|
||||
if (DauxHelper::isExternalUrl($url)) {
|
||||
$element->setAttribute('class', 'Link--external');
|
||||
$element->setAttribute('rel', 'noopener noreferrer');
|
||||
|
||||
return $element;
|
||||
}
|
||||
@ -112,16 +68,13 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
$foundWithHash = false;
|
||||
|
||||
try {
|
||||
$file = $this->resolveInternalFile($url);
|
||||
$file = DauxHelper::resolveInternalFile($this->daux, $url);
|
||||
$url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl());
|
||||
} catch (LinkNotFoundException $e) {
|
||||
|
||||
|
||||
|
||||
// For some reason, the filename could contain a # and thus the link needs to resolve to that.
|
||||
try {
|
||||
if (strlen($urlAndHash[1] ?? "") > 0) {
|
||||
$file = $this->resolveInternalFile($url . '#' . $urlAndHash[1]);
|
||||
if (strlen($urlAndHash[1] ?? '') > 0) {
|
||||
$file = DauxHelper::resolveInternalFile($this->daux, $url . '#' . $urlAndHash[1]);
|
||||
$url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl());
|
||||
$foundWithHash = true;
|
||||
}
|
||||
@ -148,4 +101,9 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
public function setConfiguration(ConfigurationInterface $configuration)
|
||||
{
|
||||
$this->parent->setConfiguration($configuration);
|
||||
}
|
||||
}
|
||||
|
@ -6,43 +6,22 @@ use League\CommonMark\Cursor;
|
||||
class TableOfContents extends AbstractBlock
|
||||
{
|
||||
/**
|
||||
* Returns true if this block can contain the given block as a child node
|
||||
*
|
||||
* @param AbstractBlock $block
|
||||
*
|
||||
* @return bool
|
||||
* Returns true if this block can contain the given block as a child node.
|
||||
*/
|
||||
public function canContain(AbstractBlock $block)
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if block type can accept lines of text
|
||||
*
|
||||
* @return bool
|
||||
* Whether this is a code block.
|
||||
*/
|
||||
public function acceptsLines()
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this is a code block
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchesNextLine(Cursor $cursor)
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1,18 +1,12 @@
|
||||
<?php namespace Todaymade\Daux\ContentTypes\Markdown;
|
||||
|
||||
use League\CommonMark\Block\Parser\AbstractBlockParser;
|
||||
use League\CommonMark\Block\Parser\BlockParserInterface;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
class TableOfContentsParser extends AbstractBlockParser
|
||||
class TableOfContentsParser implements BlockParserInterface
|
||||
{
|
||||
/**
|
||||
* @param ContextInterface $context
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function parse(ContextInterface $context, Cursor $cursor)
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
if ($cursor->isIndented()) {
|
||||
return false;
|
||||
|
236
libs/Daux.php
236
libs/Daux.php
@ -4,8 +4,6 @@ use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\ContentTypes\ContentTypeHandler;
|
||||
use Todaymade\Daux\Tree\Builder;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Root;
|
||||
|
||||
class Daux
|
||||
@ -15,8 +13,11 @@ class Daux
|
||||
|
||||
public static $output;
|
||||
|
||||
/** @var string */
|
||||
public $local_base;
|
||||
/** @var Tree\Root */
|
||||
public $tree;
|
||||
|
||||
/** @var Config */
|
||||
public $config;
|
||||
|
||||
/** @var \Todaymade\Daux\Format\Base\Generator */
|
||||
protected $generator;
|
||||
@ -24,182 +25,35 @@ class Daux
|
||||
/** @var ContentTypeHandler */
|
||||
protected $typeHandler;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
/** @var string[] */
|
||||
protected $validExtensions;
|
||||
|
||||
/** @var Processor */
|
||||
protected $processor;
|
||||
|
||||
/** @var Tree\Root */
|
||||
public $tree;
|
||||
|
||||
/** @var Config */
|
||||
public $options;
|
||||
|
||||
/** @var string */
|
||||
private $mode;
|
||||
|
||||
/** @var bool */
|
||||
private $merged_tree = false;
|
||||
|
||||
/**
|
||||
* @param string $mode
|
||||
*/
|
||||
public function __construct($mode, OutputInterface $output)
|
||||
public function __construct(Config $config, OutputInterface $output)
|
||||
{
|
||||
Daux::$output = $output;
|
||||
$this->mode = $mode;
|
||||
|
||||
$this->local_base = dirname(__DIR__);
|
||||
|
||||
// global.json
|
||||
$this->loadBaseConfiguration();
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $override_file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function initializeConfiguration($override_file = null)
|
||||
{
|
||||
$params = $this->getParams();
|
||||
|
||||
// Validate and set theme path
|
||||
$params->setDocumentationDirectory(
|
||||
$docs_path = $this->normalizeDocumentationPath($this->getParams()->getDocumentationDirectory())
|
||||
);
|
||||
|
||||
// Read documentation overrides
|
||||
$this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
||||
|
||||
// Read command line overrides
|
||||
$override_file = $this->getConfigurationOverride($override_file);
|
||||
if ($override_file !== null) {
|
||||
$params->setConfigurationOverrideFile($override_file);
|
||||
$this->loadConfiguration($override_file);
|
||||
}
|
||||
|
||||
// Validate and set theme path
|
||||
$params->setThemesPath($this->normalizeThemePath($params->getThemesDirectory()));
|
||||
|
||||
// Set a valid default timezone
|
||||
if ($params->hasTimezone()) {
|
||||
date_default_timezone_set($params->getTimezone());
|
||||
} elseif (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('GMT');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file requested for configuration overrides
|
||||
*
|
||||
* @param string|null $path
|
||||
* @return string|null the path to a file to load for configuration overrides
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getConfigurationOverride($path)
|
||||
{
|
||||
$validPath = DauxHelper::findLocation($path, $this->local_base, 'DAUX_CONFIGURATION', 'file');
|
||||
|
||||
if ($validPath === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$validPath) {
|
||||
throw new Exception('The configuration override file does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
return $validPath;
|
||||
}
|
||||
|
||||
public function normalizeThemePath($path)
|
||||
{
|
||||
$validPath = DauxHelper::findLocation($path, $this->local_base, 'DAUX_THEME', 'dir');
|
||||
|
||||
if (!$validPath) {
|
||||
throw new Exception('The Themes directory does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
return $validPath;
|
||||
|
||||
}
|
||||
|
||||
public function normalizeDocumentationPath($path)
|
||||
{
|
||||
$validPath = DauxHelper::findLocation($path, $this->local_base, 'DAUX_SOURCE', 'dir');
|
||||
|
||||
if (!$validPath) {
|
||||
throw new Exception('The Docs directory does not exist. Check the path again : ' . $path);
|
||||
}
|
||||
|
||||
return $validPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and validate the global configuration
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function loadBaseConfiguration()
|
||||
{
|
||||
$this->options = new Config();
|
||||
|
||||
// Set the default configuration
|
||||
$this->options->merge([
|
||||
'docs_directory' => 'docs',
|
||||
'valid_content_extensions' => ['md', 'markdown'],
|
||||
|
||||
//Paths and tree
|
||||
'mode' => $this->mode,
|
||||
'local_base' => $this->local_base,
|
||||
'templates' => 'templates',
|
||||
|
||||
'index_key' => 'index.html',
|
||||
'base_page' => '',
|
||||
'base_url' => '',
|
||||
]);
|
||||
|
||||
// Load the global configuration
|
||||
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . 'global.json', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $config_file
|
||||
* @param bool $optional
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function loadConfiguration($config_file, $optional = true)
|
||||
{
|
||||
if (!file_exists($config_file)) {
|
||||
if ($optional) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception('The configuration file is missing. Check path : ' . $config_file);
|
||||
}
|
||||
|
||||
$config = json_decode(file_get_contents($config_file), true);
|
||||
if (!isset($config)) {
|
||||
throw new Exception('The configuration file "' . $config_file . '" is corrupt. Is your JSON well-formed ?');
|
||||
}
|
||||
$this->options->merge($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the tree that will be used
|
||||
* Generate the tree that will be used.
|
||||
*/
|
||||
public function generateTree()
|
||||
{
|
||||
$this->options['valid_content_extensions'] = $this->getContentExtensions();
|
||||
$this->config->setValidContentExtensions($this->getContentExtensions());
|
||||
|
||||
$this->tree = new Root($this->getParams());
|
||||
Builder::build($this->tree, $this->options['ignore']);
|
||||
$this->tree = new Root($this->getConfig());
|
||||
Builder::build($this->tree, $this->config->getIgnore());
|
||||
|
||||
// Apply the language name as Section title
|
||||
if ($this->options->isMultilanguage()) {
|
||||
foreach ($this->options['languages'] as $key => $node) {
|
||||
if ($this->config->isMultilanguage()) {
|
||||
foreach ($this->config->getLanguages() as $key => $node) {
|
||||
$this->tree->getEntries()[$key]->setTitle($node);
|
||||
}
|
||||
}
|
||||
@ -216,22 +70,35 @@ class Daux
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function getParams()
|
||||
public function getConfig()
|
||||
{
|
||||
if ($this->tree && !$this->merged_tree) {
|
||||
$this->options['tree'] = $this->tree;
|
||||
$this->options['index'] = $this->tree->getIndexPage() ?: $this->tree->getFirstPage();
|
||||
if ($this->options->isMultilanguage()) {
|
||||
foreach ($this->options['languages'] as $key => $name) {
|
||||
$this->options['entry_page'][$key] = $this->tree->getEntries()[$key]->getFirstPage();
|
||||
$this->config->setTree($this->tree);
|
||||
$this->config->setIndex($this->tree->getIndexPage() ?: $this->tree->getFirstPage());
|
||||
$entry_page = null;
|
||||
if ($this->config->isMultilanguage()) {
|
||||
$entry_page = [];
|
||||
foreach ($this->config->getLanguages() as $key => $name) {
|
||||
$entry_page[$key] = $this->tree->getEntries()[$key]->getFirstPage();
|
||||
}
|
||||
} else {
|
||||
$this->options['entry_page'] = $this->tree->getFirstPage();
|
||||
$entry_page = $this->tree->getFirstPage();
|
||||
}
|
||||
$this->config->setEntryPage($entry_page);
|
||||
$this->merged_tree = true;
|
||||
}
|
||||
|
||||
return $this->options;
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*
|
||||
* @deprecated Use getConfig instead
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,17 +113,14 @@ class Daux
|
||||
return $this->processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Processor $processor
|
||||
*/
|
||||
public function setProcessor(Processor $processor)
|
||||
{
|
||||
$this->processor = $processor;
|
||||
|
||||
// This is not the cleanest but it's
|
||||
// the best i've found to use the
|
||||
// the best I've found to use the
|
||||
// processor in very remote places
|
||||
$this->options['processor_instance'] = $processor;
|
||||
$this->config->setProcessorInstance($processor);
|
||||
}
|
||||
|
||||
public function getGenerators()
|
||||
@ -272,10 +136,9 @@ class Daux
|
||||
return array_replace($default, $extended);
|
||||
}
|
||||
|
||||
|
||||
public function getProcessorClass()
|
||||
{
|
||||
$processor = $this->getParams()['processor'];
|
||||
$processor = $this->getConfig()->getProcessor();
|
||||
|
||||
if (empty($processor)) {
|
||||
return null;
|
||||
@ -293,7 +156,8 @@ class Daux
|
||||
return $class;
|
||||
}
|
||||
|
||||
protected function findAlternatives($input, $words) {
|
||||
protected function findAlternatives($input, $words)
|
||||
{
|
||||
$alternatives = [];
|
||||
|
||||
foreach ($words as $word) {
|
||||
@ -318,7 +182,7 @@ class Daux
|
||||
|
||||
$generators = $this->getGenerators();
|
||||
|
||||
$format = $this->getParams()->getFormat();
|
||||
$format = $this->getConfig()->getFormat();
|
||||
|
||||
if (!array_key_exists($format, $generators)) {
|
||||
$message = "The format '$format' doesn't exist, did you forget to set your processor ?";
|
||||
@ -365,7 +229,7 @@ class Daux
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all content file extensions
|
||||
* Get all content file extensions.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
@ -378,7 +242,8 @@ class Daux
|
||||
return $this->validExtensions = $this->getContentTypeHandler()->getContentExtensions();
|
||||
}
|
||||
|
||||
public static function getOutput() {
|
||||
public static function getOutput()
|
||||
{
|
||||
if (!Daux::$output) {
|
||||
Daux::$output = new NullOutput();
|
||||
}
|
||||
@ -389,25 +254,28 @@ class Daux
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines or a single string
|
||||
* @param array|string $messages The message as an array of lines or a single string
|
||||
* @param bool $newline Whether to add a newline
|
||||
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
|
||||
*/
|
||||
public static function write($messages, $newline = false, $options = 0) {
|
||||
public static function write($messages, $newline = false, $options = 0)
|
||||
{
|
||||
Daux::getOutput()->write($messages, $newline, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output and adds a newline at the end.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param array|string $messages The message as an array of lines of a single string
|
||||
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
|
||||
*/
|
||||
public static function writeln($messages, $options = 0) {
|
||||
public static function writeln($messages, $options = 0)
|
||||
{
|
||||
Daux::getOutput()->write($messages, true, $options);
|
||||
}
|
||||
|
||||
public static function getVerbosity() {
|
||||
public static function getVerbosity()
|
||||
{
|
||||
return Daux::getOutput()->getVerbosity();
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +1,48 @@
|
||||
<?php namespace Todaymade\Daux;
|
||||
|
||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||
use Todaymade\Daux\Tree\Builder;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
|
||||
class DauxHelper
|
||||
{
|
||||
/**
|
||||
* Set a new base_url for the configuration
|
||||
* Set a new base_url for the configuration.
|
||||
*
|
||||
* @param Config $config
|
||||
* @param string $base_url
|
||||
*/
|
||||
public static function rebaseConfiguration(Config $config, $base_url)
|
||||
{
|
||||
// Avoid changing the url if it is already correct
|
||||
if ($config['base_url'] == $base_url && !empty($config['theme'])) {
|
||||
if ($config->getBaseUrl() == $base_url && !empty($config->getTheme())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Change base url for all links on the pages
|
||||
$config['base_url'] = $config['base_page'] = $base_url;
|
||||
$config['base_url'] = $base_url;
|
||||
$config['theme'] = static::getTheme($config, $base_url);
|
||||
$config['image'] = str_replace('<base_url>', $base_url, $config['image']);
|
||||
}
|
||||
|
||||
protected static function resolveVariant(Config $params)
|
||||
{
|
||||
if (array_key_exists('theme-variant', $params['html'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_dir(realpath(($params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme'])))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$theme = explode('-', $params['html']['theme']);
|
||||
|
||||
// do we have a variant or only a theme ?
|
||||
if (isset($theme[1])) {
|
||||
$params['html']['theme-variant'] = array_pop($theme);
|
||||
$params['html']['theme'] = implode('-', $theme);
|
||||
} else {
|
||||
$params['html']['theme'] = array_pop($theme);
|
||||
}
|
||||
|
||||
if (!is_dir(realpath($params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme']))) {
|
||||
throw new \RuntimeException("Theme '{$params['html']['theme']}' not found");
|
||||
}
|
||||
$config['image'] = str_replace('<base_url>', $base_url, $config->getImage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $params
|
||||
* @param string $current_url
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getTheme(Config $params, $current_url)
|
||||
protected static function getTheme(Config $config, $current_url)
|
||||
{
|
||||
self::resolveVariant($params);
|
||||
static $cache = [];
|
||||
|
||||
$theme_folder = $params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme'];
|
||||
$theme_url = $params['base_url'] . 'themes/' . $params['html']['theme'] . '/';
|
||||
$htmlTheme = $config->getHTML()->getTheme();
|
||||
|
||||
$theme_folder = $config->getThemesPath() . DIRECTORY_SEPARATOR . $htmlTheme;
|
||||
$theme_url = $config->getBaseUrl() . 'themes/' . $htmlTheme . '/';
|
||||
|
||||
$cache_key = "$current_url-$htmlTheme";
|
||||
if (array_key_exists($cache_key, $cache)) {
|
||||
return $cache[$cache_key];
|
||||
}
|
||||
|
||||
$theme = [];
|
||||
if (is_file($theme_folder . DIRECTORY_SEPARATOR . 'config.json')) {
|
||||
@ -69,19 +52,20 @@ class DauxHelper
|
||||
}
|
||||
}
|
||||
|
||||
//Default parameters for theme
|
||||
// Default parameters for theme
|
||||
$theme += [
|
||||
'name' => $params['html']['theme'],
|
||||
'name' => $htmlTheme,
|
||||
'css' => [],
|
||||
'js' => [],
|
||||
'fonts' => [],
|
||||
'favicon' => '<base_url>themes/daux/img/favicon.png',
|
||||
'templates' => $theme_folder . DIRECTORY_SEPARATOR . 'templates',
|
||||
'variants' => [],
|
||||
'with_search' => $config->getHTML()->hasSearch()
|
||||
];
|
||||
|
||||
if (array_key_exists('theme-variant', $params['html'])) {
|
||||
$variant = $params['html']['theme-variant'];
|
||||
if ($config->getHTML()->hasThemeVariant()) {
|
||||
$variant = $config->getHTML()->getThemeVariant();
|
||||
if (!array_key_exists($variant, $theme['variants'])) {
|
||||
throw new Exception("Variant '$variant' not found for theme '$theme[name]'");
|
||||
}
|
||||
@ -101,8 +85,16 @@ class DauxHelper
|
||||
}
|
||||
}
|
||||
|
||||
if ($theme['with_search']) {
|
||||
$theme['css'][] = '<base_url>daux_libraries/search.css';
|
||||
}
|
||||
|
||||
if (is_file($config->getDocumentationDirectory() . DIRECTORY_SEPARATOR . 'style.css')) {
|
||||
$theme['css'][]= '<base_url>style.css';
|
||||
}
|
||||
|
||||
$substitutions = [
|
||||
'<local_base>' => $params['local_base'],
|
||||
'<local_base>' => $config->getLocalBase(),
|
||||
'<base_url>' => $current_url,
|
||||
'<theme_url>' => $theme_url,
|
||||
];
|
||||
@ -117,13 +109,16 @@ class DauxHelper
|
||||
}
|
||||
}
|
||||
|
||||
$cache[$cache_key] = $theme;
|
||||
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all '/./' and '/../' in a path, without actually checking the path
|
||||
* Remove all '/./' and '/../' in a path, without actually checking the path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCleanPath($path)
|
||||
@ -148,13 +143,13 @@ class DauxHelper
|
||||
/**
|
||||
* Get the possible output file names for a source file.
|
||||
*
|
||||
* @param Config $config
|
||||
* @param string $part
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getFilenames(Config $config, $part)
|
||||
{
|
||||
$extensions = implode('|', array_map('preg_quote', $config['valid_content_extensions'])) . '|html';
|
||||
$extensions = implode('|', array_map('preg_quote', $config->getValidContentExtensions())) . '|html';
|
||||
|
||||
$raw = preg_replace('/(.*)?\\.(' . $extensions . ')$/', '$1', $part);
|
||||
$raw = Builder::removeSortingInformations($raw);
|
||||
@ -163,11 +158,12 @@ class DauxHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate a file in the tree. Returns the file if found or false
|
||||
* Locate a file in the tree. Returns the file if found or false.
|
||||
*
|
||||
* @param Directory $tree
|
||||
* @param string $request
|
||||
* @return Tree\Content|Tree\Raw|false
|
||||
*
|
||||
* @return false|Tree\Content|Tree\Raw
|
||||
*/
|
||||
public static function getFile($tree, $request)
|
||||
{
|
||||
@ -186,16 +182,24 @@ class DauxHelper
|
||||
|
||||
if ($node == '..') {
|
||||
$tree = $tree->getParent();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$node = DauxHelper::slug(urldecode($node));
|
||||
|
||||
// if the node exists in the current request tree,
|
||||
// change the $tree variable to reference the new
|
||||
// node and proceed to the next url part
|
||||
if (isset($tree->getEntries()[$node])) {
|
||||
$tree = $tree->getEntries()[$node];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// We try a second time by decoding the url
|
||||
$node = DauxHelper::slug(urldecode($node));
|
||||
if (isset($tree->getEntries()[$node])) {
|
||||
$tree = $tree->getEntries()[$node];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -205,6 +209,7 @@ class DauxHelper
|
||||
foreach (static::getFilenames($tree->getConfig(), $node) as $filename) {
|
||||
if (isset($tree->getEntries()[$filename])) {
|
||||
$tree = $tree->getEntries()[$filename];
|
||||
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
@ -237,15 +242,18 @@ class DauxHelper
|
||||
* Taken from Stringy
|
||||
*
|
||||
* @param string $title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function slug($title)
|
||||
{
|
||||
// Convert to ASCII
|
||||
foreach (static::charsArray() as $key => $value) {
|
||||
$title = str_replace($value, $key, $title);
|
||||
if (function_exists('transliterator_transliterate')) {
|
||||
$title = transliterator_transliterate('Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC;', $title);
|
||||
}
|
||||
|
||||
$title = iconv('utf-8', 'ASCII//TRANSLIT//IGNORE', $title);
|
||||
|
||||
// Remove unsupported characters
|
||||
$title = preg_replace('/[^\x20-\x7E]/u', '', $title);
|
||||
|
||||
@ -263,149 +271,10 @@ class DauxHelper
|
||||
return trim($title, $separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the replacements for the slug() method.
|
||||
*
|
||||
* Taken from Stringy
|
||||
*
|
||||
* @return array An array of replacements.
|
||||
*/
|
||||
public static function charsArray()
|
||||
{
|
||||
static $charsArray;
|
||||
|
||||
if (isset($charsArray)) {
|
||||
return $charsArray;
|
||||
}
|
||||
|
||||
return $charsArray = [
|
||||
'a' => [
|
||||
'à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ',
|
||||
'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ä', 'ā', 'ą',
|
||||
'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ',
|
||||
'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ',
|
||||
'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', ],
|
||||
'b' => ['б', 'β', 'Ъ', 'Ь', 'ب'],
|
||||
'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'],
|
||||
'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ',
|
||||
'д', 'δ', 'د', 'ض', ],
|
||||
'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ',
|
||||
'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ',
|
||||
'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э',
|
||||
'є', 'ə', ],
|
||||
'f' => ['ф', 'φ', 'ف'],
|
||||
'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ج'],
|
||||
'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه'],
|
||||
'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į',
|
||||
'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ',
|
||||
'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ',
|
||||
'ῗ', 'і', 'ї', 'и', ],
|
||||
'j' => ['ĵ', 'ј', 'Ј'],
|
||||
'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك'],
|
||||
'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل'],
|
||||
'm' => ['м', 'μ', 'م'],
|
||||
'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن'],
|
||||
'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ',
|
||||
'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő',
|
||||
'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό',
|
||||
'ö', 'о', 'و', 'θ', ],
|
||||
'p' => ['п', 'π'],
|
||||
'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر'],
|
||||
's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص'],
|
||||
't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط'],
|
||||
'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ',
|
||||
'ự', 'ü', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', ],
|
||||
'v' => ['в'],
|
||||
'w' => ['ŵ', 'ω', 'ώ'],
|
||||
'x' => ['χ'],
|
||||
'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ',
|
||||
'ϋ', 'ύ', 'ΰ', 'ي', ],
|
||||
'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز'],
|
||||
'aa' => ['ع'],
|
||||
'ae' => ['æ'],
|
||||
'ch' => ['ч'],
|
||||
'dj' => ['ђ', 'đ'],
|
||||
'dz' => ['џ'],
|
||||
'gh' => ['غ'],
|
||||
'kh' => ['х', 'خ'],
|
||||
'lj' => ['љ'],
|
||||
'nj' => ['њ'],
|
||||
'oe' => ['œ'],
|
||||
'ps' => ['ψ'],
|
||||
'sh' => ['ш'],
|
||||
'shch' => ['щ'],
|
||||
'ss' => ['ß'],
|
||||
'th' => ['þ', 'ث', 'ذ', 'ظ'],
|
||||
'ts' => ['ц'],
|
||||
'ya' => ['я'],
|
||||
'yu' => ['ю'],
|
||||
'zh' => ['ж'],
|
||||
'(c)' => ['©'],
|
||||
'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ',
|
||||
'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Ä', 'Å', 'Ā',
|
||||
'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ',
|
||||
'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ',
|
||||
'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', ],
|
||||
'B' => ['Б', 'Β'],
|
||||
'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ'],
|
||||
'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'],
|
||||
'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ',
|
||||
'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
|
||||
'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э',
|
||||
'Є', 'Ə', ],
|
||||
'F' => ['Ф', 'Φ'],
|
||||
'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'],
|
||||
'H' => ['Η', 'Ή'],
|
||||
'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į',
|
||||
'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ',
|
||||
'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', ],
|
||||
'K' => ['К', 'Κ'],
|
||||
'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ'],
|
||||
'M' => ['М', 'Μ'],
|
||||
'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'],
|
||||
'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ',
|
||||
'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ö', 'Ø', 'Ō',
|
||||
'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ',
|
||||
'Ὸ', 'Ό', 'О', 'Θ', 'Ө', ],
|
||||
'P' => ['П', 'Π'],
|
||||
'R' => ['Ř', 'Ŕ', 'Р', 'Ρ'],
|
||||
'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'],
|
||||
'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'],
|
||||
'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ',
|
||||
'Ự', 'Û', 'Ü', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', ],
|
||||
'V' => ['В'],
|
||||
'W' => ['Ω', 'Ώ'],
|
||||
'X' => ['Χ'],
|
||||
'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ',
|
||||
'Ы', 'Й', 'Υ', 'Ϋ', ],
|
||||
'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'],
|
||||
'AE' => ['Æ'],
|
||||
'CH' => ['Ч'],
|
||||
'DJ' => ['Ђ'],
|
||||
'DZ' => ['Џ'],
|
||||
'KH' => ['Х'],
|
||||
'LJ' => ['Љ'],
|
||||
'NJ' => ['Њ'],
|
||||
'PS' => ['Ψ'],
|
||||
'SH' => ['Ш'],
|
||||
'SHCH' => ['Щ'],
|
||||
'SS' => ['ẞ'],
|
||||
'TH' => ['Þ'],
|
||||
'TS' => ['Ц'],
|
||||
'YA' => ['Я'],
|
||||
'YU' => ['Ю'],
|
||||
'ZH' => ['Ж'],
|
||||
' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81",
|
||||
"\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84",
|
||||
"\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87",
|
||||
"\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A",
|
||||
"\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80", ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getRelativePath($from, $to)
|
||||
@ -432,10 +301,10 @@ class DauxHelper
|
||||
// add traversals up to first matching dir
|
||||
$padLength = (count($relPath) + $remaining - 1) * -1;
|
||||
$relPath = array_pad($relPath, $padLength, '..');
|
||||
|
||||
break;
|
||||
} else {
|
||||
//$relPath[0] = './' . $relPath[0];
|
||||
}
|
||||
//$relPath[0] = './' . $relPath[0];
|
||||
}
|
||||
}
|
||||
|
||||
@ -446,11 +315,13 @@ class DauxHelper
|
||||
{
|
||||
if (!is_string($path)) {
|
||||
$mess = sprintf('String expected but was given %s', gettype($path));
|
||||
|
||||
throw new \InvalidArgumentException($mess);
|
||||
}
|
||||
|
||||
if (!ctype_print($path)) {
|
||||
$mess = 'Path can NOT have non-printable characters or be empty';
|
||||
|
||||
throw new \DomainException($mess);
|
||||
}
|
||||
|
||||
@ -466,13 +337,15 @@ class DauxHelper
|
||||
$parts = [];
|
||||
if (!preg_match($regExp, $path, $parts)) {
|
||||
$mess = sprintf('Path is NOT valid, was given %s', $path);
|
||||
|
||||
throw new \DomainException($mess);
|
||||
}
|
||||
|
||||
return '' !== $parts['root'];
|
||||
}
|
||||
|
||||
public static function getAbsolutePath($path) {
|
||||
public static function getAbsolutePath($path)
|
||||
{
|
||||
if (DauxHelper::isAbsolutePath($path)) {
|
||||
return $path;
|
||||
}
|
||||
@ -480,45 +353,58 @@ class DauxHelper
|
||||
return getcwd() . '/' . $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $path
|
||||
* @param string $basedir
|
||||
* @param string $var The constant name to check
|
||||
* @param "dir"|"file" $type
|
||||
* @return false|null|string
|
||||
*/
|
||||
public static function findLocation($path, $basedir, $var, $type) {
|
||||
// VFS, used only in tests
|
||||
if (substr($path, 0, 6) == "vfs://") {
|
||||
return $path;
|
||||
}
|
||||
|
||||
// When running through `daux --serve` we set an environment variable to know where we started from
|
||||
$env = getenv($var);
|
||||
if ($env && DauxHelper::is($env, $type)) {
|
||||
return $env;
|
||||
}
|
||||
|
||||
// If Path is explicitly null, it's useless to go further
|
||||
if ($path == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if it's relative to the current directory or an absolute path
|
||||
if (DauxHelper::is($path, $type)) {
|
||||
return DauxHelper::getAbsolutePath($path);
|
||||
}
|
||||
|
||||
// Check if it exists relative to Daux's root
|
||||
$newPath = $basedir . DIRECTORY_SEPARATOR . $path;
|
||||
if (DauxHelper::is($newPath, $type)) {
|
||||
return $newPath;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function is($path, $type) {
|
||||
public static function is($path, $type)
|
||||
{
|
||||
return ($type == 'dir') ? is_dir($path) : file_exists($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param string $url
|
||||
*
|
||||
* @throws LinkNotFoundException
|
||||
*
|
||||
* @return Entry
|
||||
*/
|
||||
public static function resolveInternalFile($config, $url)
|
||||
{
|
||||
$triedAbsolute = false;
|
||||
|
||||
// Legacy absolute paths could start with
|
||||
// "!" In this case we will try to find
|
||||
// the file starting at the root
|
||||
if ($url[0] == '!' || $url[0] == '/') {
|
||||
$url = ltrim($url, '!/');
|
||||
|
||||
if ($file = DauxHelper::getFile($config->getTree(), $url)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
$triedAbsolute = true;
|
||||
}
|
||||
|
||||
// Seems it's not an absolute path or not found,
|
||||
// so we'll continue with the current folder
|
||||
if ($file = DauxHelper::getFile($config->getCurrentPage()->getParent(), $url)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
// If we didn't already try it, we'll
|
||||
// do a pass starting at the root
|
||||
if (!$triedAbsolute && $file = DauxHelper::getFile($config->getTree(), $url)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
throw new LinkNotFoundException("Could not locate file '$url'");
|
||||
}
|
||||
|
||||
public static function isValidUrl($url)
|
||||
{
|
||||
return !empty($url) && $url[0] != '#';
|
||||
}
|
||||
|
||||
public static function isExternalUrl($url)
|
||||
{
|
||||
return preg_match('#^(?:[a-z]+:)?//|^mailto:#', $url);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ abstract class ContentPage extends SimplePage
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $params;
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var ContentType
|
||||
@ -38,9 +38,17 @@ abstract class ContentPage extends SimplePage
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
public function setParams(Config $params)
|
||||
public function setConfig(Config $config)
|
||||
{
|
||||
$this->params = $params;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use setConfig instead
|
||||
*/
|
||||
public function setParams(Config $config)
|
||||
{
|
||||
$this->setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,11 +73,11 @@ abstract class ContentPage extends SimplePage
|
||||
return $this->getPureContent();
|
||||
}
|
||||
|
||||
public static function fromFile(Content $file, $params, ContentType $contentType)
|
||||
public static function fromFile(Content $file, $config, ContentType $contentType)
|
||||
{
|
||||
$page = new static($file->getTitle(), $file->getContent());
|
||||
$page->setFile($file);
|
||||
$page->setParams($params);
|
||||
$page->setConfig($config);
|
||||
$page->setContentType($contentType);
|
||||
|
||||
return $page;
|
||||
|
@ -3,7 +3,7 @@
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: onigoetz
|
||||
* Date: 06/11/15
|
||||
* Time: 20:27
|
||||
* Time: 20:27.
|
||||
*/
|
||||
namespace Todaymade\Daux\Format\Base;
|
||||
|
||||
@ -25,7 +25,7 @@ class EmbedImages
|
||||
{
|
||||
return preg_replace_callback(
|
||||
"/<img\\s+[^>]*src=['\"]([^\"]*)['\"][^>]*>/",
|
||||
function($matches) use ($file, $callback) {
|
||||
function ($matches) use ($file, $callback) {
|
||||
if ($result = $this->findImage($matches[1], $matches[0], $file, $callback)) {
|
||||
return $result;
|
||||
}
|
||||
@ -67,7 +67,6 @@ class EmbedImages
|
||||
//Get any file corresponding to the right one
|
||||
$file = DauxHelper::getFile($this->tree, $url);
|
||||
|
||||
|
||||
if ($file === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -6,15 +6,11 @@ use Todaymade\Daux\Daux;
|
||||
|
||||
interface Generator
|
||||
{
|
||||
/**
|
||||
* @param Daux $daux
|
||||
*/
|
||||
public function __construct(Daux $daux);
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @param int $width
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function generateAll(InputInterface $input, OutputInterface $output, $width);
|
||||
|
@ -6,9 +6,7 @@ use Todaymade\Daux\Tree\Entry;
|
||||
interface LiveGenerator extends Generator
|
||||
{
|
||||
/**
|
||||
* @param Entry $node
|
||||
* @param Config $params
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
*/
|
||||
public function generateOne(Entry $node, Config $params);
|
||||
public function generateOne(Entry $node, Config $config);
|
||||
}
|
||||
|
@ -3,14 +3,14 @@
|
||||
interface Page
|
||||
{
|
||||
/**
|
||||
* Get the converted content, without any template
|
||||
* Get the converted content, without any template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPureContent();
|
||||
|
||||
/**
|
||||
* Get the full content
|
||||
* Get the full content.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -24,7 +24,8 @@ class Api
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is public due to test purposes
|
||||
* This method is public due to test purposes.
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
public function getClient()
|
||||
@ -39,9 +40,8 @@ class Api
|
||||
|
||||
/**
|
||||
* The standard error message from guzzle is quite poor in informations,
|
||||
* this will give little bit more sense to it and return it
|
||||
* this will give little bit more sense to it and return it.
|
||||
*
|
||||
* @param BadResponseException $e
|
||||
* @return \Exception
|
||||
*/
|
||||
protected function handleError(BadResponseException $e)
|
||||
@ -101,10 +101,11 @@ class Api
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of pages
|
||||
* Get a list of pages.
|
||||
*
|
||||
* @param int $rootPage
|
||||
* @param bool $recursive
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList($rootPage, $recursive = false)
|
||||
@ -153,6 +154,7 @@ class Api
|
||||
* @param int $parent_id
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function createPage($parent_id, $title, $content)
|
||||
@ -218,8 +220,13 @@ class Api
|
||||
public function showSourceCode($css, $lineNumber, $column)
|
||||
{
|
||||
$lines = preg_split("/\r?\n/", $css);
|
||||
|
||||
if ($lines === false) {
|
||||
return $css;
|
||||
}
|
||||
|
||||
$start = max($lineNumber - 3, 0);
|
||||
$end = min($lineNumber + 2, count($lines));
|
||||
$end = min($lineNumber + 2, count($lines));
|
||||
|
||||
$maxWidth = strlen("$end");
|
||||
|
||||
@ -227,12 +234,11 @@ class Api
|
||||
|
||||
$prepared = [];
|
||||
foreach ($filtered as $index => $line) {
|
||||
|
||||
$number = $start + 1 + $index;
|
||||
$gutter = substr(' ' . (' ' . $number), -$maxWidth) . ' | ';
|
||||
|
||||
if ($number == $lineNumber) {
|
||||
$spacing = str_repeat(" ", strlen($gutter) + $column - 2);
|
||||
$spacing = str_repeat(' ', strlen($gutter) + $column - 2);
|
||||
$prepared[] = '>' . $gutter . $line . "\n " . $spacing . '^';
|
||||
} else {
|
||||
$prepared[] = ' ' . $gutter . $line;
|
||||
@ -243,9 +249,10 @@ class Api
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a page
|
||||
* Delete a page.
|
||||
*
|
||||
* @param int $page_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function deletePage($page_id)
|
||||
@ -263,6 +270,7 @@ class Api
|
||||
// this name is uploaded
|
||||
try {
|
||||
$url = "content/$id/child/attachment?filename=" . urlencode($attachment['filename']);
|
||||
|
||||
return json_decode($this->getClient()->get($url)->getBody(), true);
|
||||
} catch (BadResponseException $e) {
|
||||
throw $this->handleError($e);
|
||||
@ -313,9 +321,9 @@ class Api
|
||||
// If the attachment is already uploaded,
|
||||
// the update URL is different
|
||||
if (count($result['results'])) {
|
||||
|
||||
if ($this->getFileSize($attachment) == $result['results'][0]['extensions']['fileSize']) {
|
||||
$write(" ( An attachment of the same size already exists, skipping. )");
|
||||
$write(' ( An attachment of the same size already exists, skipping. )');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
80
libs/Format/Confluence/Config.php
Normal file
80
libs/Format/Confluence/Config.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php namespace Todaymade\Daux\Format\Confluence;
|
||||
|
||||
use Todaymade\Daux\BaseConfig;
|
||||
|
||||
class Config extends BaseConfig
|
||||
{
|
||||
public function shouldAutoDeleteOrphanedPages()
|
||||
{
|
||||
if ($this->hasValue('delete')) {
|
||||
return $this->getValue('delete');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUpdateThreshold()
|
||||
{
|
||||
return $this->hasValue('update_threshold') ? $this->getValue('update_threshold') : 2;
|
||||
}
|
||||
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->getValue('prefix');
|
||||
}
|
||||
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return $this->getValue('base_url');
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->getValue('user');
|
||||
}
|
||||
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->getValue('pass');
|
||||
}
|
||||
|
||||
public function getSpaceId()
|
||||
{
|
||||
return $this->getValue('space_id');
|
||||
}
|
||||
|
||||
public function hasAncestorId()
|
||||
{
|
||||
return $this->hasValue('ancestor_id');
|
||||
}
|
||||
|
||||
public function getAncestorId()
|
||||
{
|
||||
return $this->getValue('ancestor_id');
|
||||
}
|
||||
|
||||
public function setAncestorId($value)
|
||||
{
|
||||
$this->setValue('ancestor_id', $value);
|
||||
}
|
||||
|
||||
public function hasRootId()
|
||||
{
|
||||
return $this->hasValue('root_id');
|
||||
}
|
||||
|
||||
public function getRootId()
|
||||
{
|
||||
return $this->getValue('root_id');
|
||||
}
|
||||
|
||||
public function hasHeader()
|
||||
{
|
||||
return $this->hasValue('header');
|
||||
}
|
||||
|
||||
public function getHeader()
|
||||
{
|
||||
return $this->getValue('header');
|
||||
}
|
||||
}
|
@ -15,17 +15,16 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
|
||||
//Embed images
|
||||
// We do it after generation so we can catch the images that were in html already
|
||||
$content = (new EmbedImages($this->params['tree']))
|
||||
$content = (new EmbedImages($this->config->getTree()))
|
||||
->embed(
|
||||
$content,
|
||||
$this->file,
|
||||
function($src, array $attributes, Entry $file) {
|
||||
|
||||
function ($src, array $attributes, Entry $file) {
|
||||
//Add the attachment for later upload
|
||||
if ($file instanceof Raw) {
|
||||
$filename = basename($file->getPath());
|
||||
$this->attachments[$filename] = ['filename' => $filename, 'file' => $file];
|
||||
} else if ($file instanceof ComputedRaw) {
|
||||
} elseif ($file instanceof ComputedRaw) {
|
||||
$filename = $file->getUri();
|
||||
$this->attachments[$filename] = ['filename' => $filename, 'content' => $file->getContent()];
|
||||
} else {
|
||||
@ -36,20 +35,20 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$intro = '';
|
||||
if (array_key_exists('confluence', $this->params) && array_key_exists('header', $this->params['confluence']) && !empty($this->params['confluence']['header'])) {
|
||||
$intro = '<ac:structured-macro ac:name="info"><ac:rich-text-body>' . $this->params['confluence']['header'] . '</ac:rich-text-body></ac:structured-macro>';
|
||||
if ($this->config->getConfluenceConfiguration()->hasHeader()) {
|
||||
$intro = '<ac:structured-macro ac:name="info"><ac:rich-text-body>' . $this->config->getConfluenceConfiguration()->getHeader() . '</ac:rich-text-body></ac:structured-macro>';
|
||||
}
|
||||
|
||||
return $intro . $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an image tag for the specified filename
|
||||
* Create an image tag for the specified filename.
|
||||
*
|
||||
* @param string $filename
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createImageTag($filename, $attributes)
|
||||
@ -61,7 +60,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
$re = '/float:\s*?(left|right);?/';
|
||||
if (preg_match($re, $value, $matches)) {
|
||||
$img .= ' ac:align="' . $matches[1] . '"';
|
||||
$value = preg_replace($re, "", $value, 1);
|
||||
$value = preg_replace($re, '', $value, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,9 @@ use League\CommonMark\HtmlElement;
|
||||
|
||||
abstract class CodeRenderer implements BlockRendererInterface
|
||||
{
|
||||
|
||||
public function escapeCDATA($content)
|
||||
{
|
||||
return str_replace("]]>", "]]]]><![CDATA[>", $content);
|
||||
return str_replace(']]>', ']]]]><![CDATA[>', $content);
|
||||
}
|
||||
|
||||
public function getHTMLElement($body, $language)
|
||||
|
@ -1,7 +1,10 @@
|
||||
<?php namespace Todaymade\Daux\Format\Confluence\ContentTypes\Markdown;
|
||||
|
||||
use League\CommonMark\Block\Element as BlockElement;
|
||||
use League\CommonMark\Environment;
|
||||
use League\CommonMark\Inline\Element as InlineElement;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||
|
||||
class CommonMarkConverter extends \Todaymade\Daux\ContentTypes\Markdown\CommonMarkConverter
|
||||
{
|
||||
@ -14,12 +17,12 @@ class CommonMarkConverter extends \Todaymade\Daux\ContentTypes\Markdown\CommonMa
|
||||
{
|
||||
parent::extendEnvironment($environment, $config);
|
||||
|
||||
$environment->addBlockRenderer('Todaymade\Daux\ContentTypes\Markdown\TableOfContents', new TOCRenderer());
|
||||
$environment->addBlockRenderer(TableOfContents::class, new TOCRenderer());
|
||||
|
||||
//Add code renderer
|
||||
$environment->addBlockRenderer('FencedCode', new FencedCodeRenderer());
|
||||
$environment->addBlockRenderer('IndentedCode', new IndentedCodeRenderer());
|
||||
$environment->addBlockRenderer(BlockElement\FencedCode::class, new FencedCodeRenderer());
|
||||
$environment->addBlockRenderer(BlockElement\IndentedCode::class, new IndentedCodeRenderer());
|
||||
|
||||
$environment->addInlineRenderer('Image', new ImageRenderer());
|
||||
$environment->addInlineRenderer(InlineElement\Image::class, new ImageRenderer());
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
<?php namespace Todaymade\Daux\Format\Confluence\ContentTypes\Markdown;
|
||||
|
||||
use Todaymade\Daux\Config;
|
||||
|
||||
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
||||
{
|
||||
public function __construct(Config $config)
|
||||
protected function createConverter()
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
||||
return new CommonMarkConverter(['daux' => $this->config]);
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ class FencedCodeRenderer extends CodeRenderer
|
||||
protected $known_conversions = ['html' => 'html/xml', 'xml' => 'html/xml', 'js' => 'javascript'];
|
||||
|
||||
/**
|
||||
* @param AbstractBlock $block
|
||||
* @param HtmlRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement|string
|
||||
@ -48,18 +46,18 @@ class FencedCodeRenderer extends CodeRenderer
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
$language = $this->getLanguage($block->getInfoWords(), $htmlRenderer);
|
||||
$language = $this->getLanguage($block->getInfoWords());
|
||||
|
||||
return $this->getHTMLElement($block->getStringContent(), $language);
|
||||
}
|
||||
|
||||
public function getLanguage($infoWords, ElementRendererInterface $htmlRenderer)
|
||||
public function getLanguage($infoWords)
|
||||
{
|
||||
if (count($infoWords) === 0 || strlen($infoWords[0]) === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$language = Xml::escape($infoWords[0], true);
|
||||
$language = Xml::escape($infoWords[0]);
|
||||
|
||||
if (array_key_exists($language, $this->known_conversions)) {
|
||||
$language = $this->known_conversions[$language];
|
||||
|
@ -4,12 +4,29 @@ use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
use League\CommonMark\Inline\Element\AbstractInline;
|
||||
use League\CommonMark\Inline\Element\Image;
|
||||
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
|
||||
use League\CommonMark\Util\ConfigurationAwareInterface;
|
||||
use League\CommonMark\Util\ConfigurationInterface;
|
||||
|
||||
class ImageRenderer extends \League\CommonMark\Inline\Renderer\ImageRenderer
|
||||
class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigurationInterface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \League\CommonMark\Inline\Renderer\ImageRenderer
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->parent = new \League\CommonMark\Inline\Renderer\ImageRenderer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Image $inline
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
@ -28,6 +45,11 @@ class ImageRenderer extends \League\CommonMark\Inline\Renderer\ImageRenderer
|
||||
);
|
||||
}
|
||||
|
||||
return parent::render($inline, $htmlRenderer);
|
||||
return $this->parent->render($inline, $htmlRenderer);
|
||||
}
|
||||
|
||||
public function setConfiguration(ConfigurationInterface $configuration)
|
||||
{
|
||||
$this->parent->setConfiguration($configuration);
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ use League\CommonMark\HtmlElement;
|
||||
class IndentedCodeRenderer extends CodeRenderer
|
||||
{
|
||||
/**
|
||||
* @param AbstractBlock $block
|
||||
* @param HtmlRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement
|
||||
@ -20,6 +18,6 @@ class IndentedCodeRenderer extends CodeRenderer
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
return $this->getHTMLElement($block->getStringContent(), "");
|
||||
return $this->getHTMLElement($block->getStringContent(), '');
|
||||
}
|
||||
}
|
||||
|
@ -4,26 +4,19 @@ use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
use League\CommonMark\Inline\Element\AbstractInline;
|
||||
use League\CommonMark\Inline\Element\Link;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
|
||||
class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
{
|
||||
/**
|
||||
* @param AbstractInline|Link $inline
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
// This can't be in the method type as
|
||||
// the method is an abstract and should
|
||||
// have the same interface
|
||||
if (!$inline instanceof Link) {
|
||||
throw new \RuntimeException(
|
||||
'Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ .
|
||||
" the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" .
|
||||
get_class($inline) . "' was provided"
|
||||
);
|
||||
if (!($inline instanceof Link)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
// Default handling
|
||||
@ -33,19 +26,29 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
|
||||
// empty urls, anchors and absolute urls
|
||||
// should not go through the url resolver
|
||||
if (!$this->isValidUrl($url) || $this->isExternalUrl($url)) {
|
||||
if (!DauxHelper::isValidUrl($url) || DauxHelper::isExternalUrl($url)) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
//Internal links
|
||||
$file = $this->resolveInternalFile($url);
|
||||
// if there's a hash component in the url, ensure we
|
||||
// don't put that part through the resolver.
|
||||
$urlAndHash = explode('#', $url);
|
||||
$url = $urlAndHash[0];
|
||||
|
||||
$link_props = [
|
||||
//Internal links
|
||||
$file = DauxHelper::resolveInternalFile($this->daux, $url);
|
||||
|
||||
$link_props = [];
|
||||
if (isset($urlAndHash[1])) {
|
||||
$link_props["ac:anchor"] = $urlAndHash[1];
|
||||
}
|
||||
|
||||
$page_props = [
|
||||
'ri:content-title' => trim(trim($this->daux['confluence']['prefix']) . ' ' . $file->getTitle()),
|
||||
'ri:space-key' => $this->daux['confluence']['space_id'],
|
||||
];
|
||||
|
||||
$page = strval(new HtmlElement('ri:page', $link_props, '', true));
|
||||
$page = strval(new HtmlElement('ri:page', $page_props, '', true));
|
||||
$children = $htmlRenderer->renderInlines($inline->children());
|
||||
if (strpos($children, '<') !== false) {
|
||||
$children = '<ac:link-body>' . $children . '</ac:link-body>';
|
||||
@ -53,6 +56,6 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
$children = '<ac:plain-text-link-body><![CDATA[' . $children . ']]></ac:plain-text-link-body>';
|
||||
}
|
||||
|
||||
return new HtmlElement('ac:link', [], $page . $children);
|
||||
return new HtmlElement('ac:link', $link_props, $page . $children);
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,16 @@
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||
|
||||
class TOCRenderer implements BlockRendererInterface
|
||||
{
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof TableOfContents)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
return '<ac:structured-macro ac:name="toc"></ac:structured-macro>';
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\Config as GlobalConfig;
|
||||
use Todaymade\Daux\Console\RunAction;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
@ -18,9 +18,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
/** @var Daux */
|
||||
protected $daux;
|
||||
|
||||
/**
|
||||
* @param Daux $daux
|
||||
*/
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
@ -30,7 +27,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
|
||||
public function checkConfiguration()
|
||||
{
|
||||
$config = $this->daux->getParams();
|
||||
$config = $this->daux->getConfig();
|
||||
$confluence = $config->getConfluenceConfiguration();
|
||||
|
||||
if ($confluence == null) {
|
||||
@ -40,7 +37,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
$mandatory = ['space_id', 'base_url', 'user', 'pass', 'prefix'];
|
||||
$errors = [];
|
||||
foreach ($mandatory as $key) {
|
||||
if (!array_key_exists($key, $confluence)) {
|
||||
if (!$confluence->hasValue($key)) {
|
||||
$errors[] = $key;
|
||||
}
|
||||
}
|
||||
@ -49,7 +46,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
throw new \RuntimeException("The following options are mandatory for confluence : '" . implode("', '", $errors) . "'");
|
||||
}
|
||||
|
||||
if (!array_key_exists('ancestor_id', $confluence) && !array_key_exists('root_id', $confluence)) {
|
||||
if (!$confluence->hasAncestorId() && !$confluence->hasRootId()) {
|
||||
throw new \RuntimeException("You must specify an 'ancestor_id' or a 'root_id' for confluence.");
|
||||
}
|
||||
}
|
||||
@ -60,7 +57,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
public function getContentTypes()
|
||||
{
|
||||
return [
|
||||
new ContentTypes\Markdown\ContentType($this->daux->getParams()),
|
||||
new ContentTypes\Markdown\ContentType($this->daux->getConfig()),
|
||||
];
|
||||
}
|
||||
|
||||
@ -69,10 +66,10 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
*/
|
||||
public function generateAll(InputInterface $input, OutputInterface $output, $width)
|
||||
{
|
||||
$params = $this->daux->getParams();
|
||||
$config = $this->daux->getConfig();
|
||||
|
||||
$confluence = $params['confluence'];
|
||||
$this->prefix = trim($confluence['prefix']) . ' ';
|
||||
$confluence = $config->getConfluenceConfiguration();
|
||||
$this->prefix = trim($confluence->getPrefix()) . ' ';
|
||||
if ($this->prefix == ' ') {
|
||||
$this->prefix = '';
|
||||
}
|
||||
@ -80,9 +77,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
$tree = $this->runAction(
|
||||
'Generating Tree ...',
|
||||
$width,
|
||||
function() use ($params) {
|
||||
$tree = $this->generateRecursive($this->daux->tree, $params);
|
||||
$tree['title'] = $this->prefix . $params['title'];
|
||||
function () use ($config) {
|
||||
$tree = $this->generateRecursive($this->daux->tree, $config);
|
||||
$tree['title'] = $this->prefix . $config->getTitle();
|
||||
|
||||
return $tree;
|
||||
}
|
||||
@ -96,31 +93,31 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
$publisher->publish($tree);
|
||||
}
|
||||
|
||||
private function generateRecursive(Directory $tree, Config $params, $base_url = '')
|
||||
private function generateRecursive(Directory $tree, GlobalConfig $config, $base_url = '')
|
||||
{
|
||||
$final = ['title' => $this->prefix . $tree->getTitle()];
|
||||
$params['base_url'] = $params['base_page'] = $base_url;
|
||||
$config['base_url'] = $base_url;
|
||||
|
||||
$params['image'] = str_replace('<base_url>', $base_url, $params['image']);
|
||||
$config->setImage(str_replace('<base_url>', $base_url, $config->getImage()));
|
||||
if ($base_url !== '') {
|
||||
$params['entry_page'] = $tree->getFirstPage();
|
||||
$config->setEntryPage($tree->getFirstPage());
|
||||
}
|
||||
foreach ($tree->getEntries() as $key => $node) {
|
||||
if ($node instanceof Directory) {
|
||||
$final['children'][$this->prefix . $node->getTitle()] = $this->generateRecursive(
|
||||
$node,
|
||||
$params,
|
||||
$config,
|
||||
'../' . $base_url
|
||||
);
|
||||
} elseif ($node instanceof Content) {
|
||||
$params['request'] = $node->getUrl();
|
||||
$config->setRequest($node->getUrl());
|
||||
|
||||
$contentType = $this->daux->getContentTypeHandler()->getType($node);
|
||||
|
||||
$data = [
|
||||
'title' => $this->prefix . $node->getTitle(),
|
||||
'file' => $node,
|
||||
'page' => ContentPage::fromFile($node, $params, $contentType),
|
||||
'page' => ContentPage::fromFile($node, $config, $contentType),
|
||||
];
|
||||
|
||||
if ($key == 'index.html') {
|
||||
|
@ -7,16 +7,6 @@ class Publisher
|
||||
{
|
||||
use RunAction;
|
||||
|
||||
/**
|
||||
* @var Api
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $confluence;
|
||||
|
||||
/**
|
||||
* @var int terminal width
|
||||
*/
|
||||
@ -27,15 +17,25 @@ class Publisher
|
||||
*/
|
||||
public $output;
|
||||
|
||||
/**
|
||||
* @var Api
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $confluence;
|
||||
|
||||
/**
|
||||
* @param $confluence
|
||||
*/
|
||||
public function __construct($confluence)
|
||||
public function __construct(Config $confluence)
|
||||
{
|
||||
$this->confluence = $confluence;
|
||||
|
||||
$this->client = new Api($confluence['base_url'], $confluence['user'], $confluence['pass']);
|
||||
$this->client->setSpace($confluence['space_id']);
|
||||
$this->client = new Api($confluence->getBaseUrl(), $confluence->getUser(), $confluence->getPassword());
|
||||
$this->client->setSpace($confluence->getSpaceId());
|
||||
}
|
||||
|
||||
public function run($title, $closure)
|
||||
@ -62,24 +62,23 @@ class Publisher
|
||||
);
|
||||
|
||||
$published = $this->run(
|
||||
"Create placeholder pages...",
|
||||
'Create placeholder pages...',
|
||||
function () use ($tree, $published) {
|
||||
return $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
return $this->createRecursive($this->confluence->getAncestorId(), $tree, $published);
|
||||
}
|
||||
);
|
||||
|
||||
$this->output->writeLn('Publishing updates...');
|
||||
$published = $this->updateRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
$published = $this->updateRecursive($this->confluence->getAncestorId(), $tree, $published);
|
||||
|
||||
$shouldDelete = array_key_exists('delete', $this->confluence) && $this->confluence['delete'];
|
||||
$delete = new PublisherDelete($this->output, $shouldDelete, $this->client);
|
||||
$delete = new PublisherDelete($this->output, $this->confluence->shouldAutoDeleteOrphanedPages(), $this->client);
|
||||
$delete->handle($published);
|
||||
}
|
||||
|
||||
protected function getRootPage($tree)
|
||||
{
|
||||
if (array_key_exists('ancestor_id', $this->confluence)) {
|
||||
$pages = $this->client->getList($this->confluence['ancestor_id']);
|
||||
if ($this->confluence->hasAncestorId()) {
|
||||
$pages = $this->client->getList($this->confluence->getAncestorId());
|
||||
foreach ($pages as $page) {
|
||||
if ($page['title'] == $tree['title']) {
|
||||
return $page;
|
||||
@ -87,9 +86,10 @@ class Publisher
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('root_id', $this->confluence)) {
|
||||
$published = $this->client->getPage($this->confluence['root_id']);
|
||||
$this->confluence['ancestor_id'] = $published['ancestor_id'];
|
||||
if ($this->confluence->hasRootId()) {
|
||||
$published = $this->client->getPage($this->confluence->getRootId());
|
||||
$this->confluence->setAncestorId($published['ancestor_id']);
|
||||
|
||||
return $published;
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ class Publisher
|
||||
|
||||
protected function updatePage($parent_id, $entry, $published)
|
||||
{
|
||||
$updateThreshold = array_key_exists('update_threshold', $this->confluence) ? $this->confluence['update_threshold'] : 2;
|
||||
$updateThreshold = $this->confluence->getUpdateThreshold();
|
||||
|
||||
$this->run(
|
||||
'- ' . PublisherUtilities::niceTitle($entry['file']->getUrl()),
|
||||
|
@ -13,7 +13,7 @@ class PublisherDelete
|
||||
protected $deletable;
|
||||
|
||||
/**
|
||||
* @var boolean should delete ?
|
||||
* @var bool should delete ?
|
||||
*/
|
||||
protected $delete;
|
||||
|
||||
@ -22,13 +22,12 @@ class PublisherDelete
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
public function __construct($output, $delete, $client)
|
||||
public function __construct($output, bool $delete, $client)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->delete = $delete;
|
||||
$this->client = $client;
|
||||
|
||||
|
||||
$this->deletable = [];
|
||||
}
|
||||
|
||||
@ -55,13 +54,13 @@ class PublisherDelete
|
||||
|
||||
if ($this->delete) {
|
||||
$this->doDelete();
|
||||
|
||||
} else {
|
||||
$this->displayDeletable();
|
||||
}
|
||||
}
|
||||
|
||||
protected function doDelete() {
|
||||
protected function doDelete()
|
||||
{
|
||||
$this->output->writeLn('Deleting obsolete pages...');
|
||||
foreach ($this->deletable as $id => $title) {
|
||||
$this->output->writeLn("- $title");
|
||||
@ -69,10 +68,11 @@ class PublisherDelete
|
||||
}
|
||||
}
|
||||
|
||||
protected function displayDeletable() {
|
||||
protected function displayDeletable()
|
||||
{
|
||||
$this->output->writeLn('Listing obsolete pages...');
|
||||
$this->output->writeLn("> The following pages will not be deleted, but just listed for information.");
|
||||
$this->output->writeLn("> If you want to delete these pages, you need to set the --delete flag on the command.");
|
||||
$this->output->writeLn('> The following pages will not be deleted, but just listed for information.');
|
||||
$this->output->writeLn('> If you want to delete these pages, you need to set the --delete flag on the command.');
|
||||
foreach ($this->deletable as $id => $title) {
|
||||
$this->output->writeLn("- $title");
|
||||
}
|
||||
|
@ -10,27 +10,182 @@ class Config extends BaseConfig
|
||||
|
||||
return [
|
||||
'name' => 'GitHub',
|
||||
'basepath' => (strpos($url, 'https://github.com/') === 0 ? '' : 'https://github.com/') . trim($url, '/')
|
||||
'basepath' => (strpos($url, 'https://github.com/') === 0 ? '' : 'https://github.com/') . trim($url, '/'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getEditOn()
|
||||
{
|
||||
if (array_key_exists('edit_on', $this)) {
|
||||
if (is_string($this['edit_on'])) {
|
||||
return $this->prepareGithubUrl($this['edit_on']);
|
||||
} else {
|
||||
|
||||
$this['edit_on']['basepath'] = rtrim($this['edit_on']['basepath'], '/');
|
||||
|
||||
return $this['edit_on'];
|
||||
if ($this->hasValue('edit_on')) {
|
||||
$edit_on = $this->getValue('edit_on');
|
||||
if (is_string($edit_on)) {
|
||||
return $this->prepareGithubUrl($edit_on);
|
||||
}
|
||||
$edit_on['basepath'] = rtrim($edit_on['basepath'], '/');
|
||||
|
||||
return $edit_on;
|
||||
}
|
||||
|
||||
if (array_key_exists('edit_on_github', $this)) {
|
||||
return $this->prepareGithubUrl($this['edit_on_github']);
|
||||
if ($this->hasValue('edit_on_github')) {
|
||||
return $this->prepareGithubUrl($this->getValue('edit_on_github'));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function hasSearch()
|
||||
{
|
||||
return $this->hasValue('search') && $this->getValue('search');
|
||||
}
|
||||
|
||||
public function showDateModified()
|
||||
{
|
||||
return $this->hasValue('date_modified') && $this->getValue('date_modified');
|
||||
}
|
||||
|
||||
public function showPreviousNextLinks()
|
||||
{
|
||||
if ($this->hasValue('jump_buttons')) {
|
||||
return $this->getValue('jump_buttons');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function showCodeToggle()
|
||||
{
|
||||
if ($this->hasValue('toggle_code')) {
|
||||
return $this->getValue('toggle_code');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasAutomaticTableOfContents(): bool
|
||||
{
|
||||
return $this->hasValue('auto_toc') && $this->getValue('auto_toc');
|
||||
}
|
||||
|
||||
public function hasGoogleAnalytics()
|
||||
{
|
||||
return $this->hasValue('google_analytics') && $this->getValue('google_analytics');
|
||||
}
|
||||
|
||||
public function getGoogleAnalyticsId()
|
||||
{
|
||||
return $this->getValue('google_analytics');
|
||||
}
|
||||
|
||||
public function hasPlausibleAnalyticsDomain()
|
||||
{
|
||||
return $this->hasValue('plausible_domain') && $this->getValue('plausible_domain');
|
||||
}
|
||||
|
||||
public function getPlausibleAnalyticsDomain()
|
||||
{
|
||||
return $this->getValue('plausible_domain');
|
||||
}
|
||||
|
||||
public function hasPiwikAnalytics()
|
||||
{
|
||||
return $this->getValue('piwik_analytics') && $this->hasValue('piwik_analytics_id');
|
||||
}
|
||||
|
||||
public function getPiwikAnalyticsId()
|
||||
{
|
||||
return $this->getValue('piwik_analytics_id');
|
||||
}
|
||||
|
||||
public function getPiwikAnalyticsUrl()
|
||||
{
|
||||
return $this->getValue('piwik_analytics');
|
||||
}
|
||||
|
||||
public function hasPoweredBy()
|
||||
{
|
||||
return $this->hasValue('powered_by') && !empty($this->getValue('powered_by'));
|
||||
}
|
||||
|
||||
public function getPoweredBy()
|
||||
{
|
||||
return $this->getValue('powered_by');
|
||||
}
|
||||
|
||||
public function hasTwitterHandles()
|
||||
{
|
||||
return $this->hasValue('twitter') && !empty($this->getValue('twitter'));
|
||||
}
|
||||
|
||||
public function getTwitterHandles()
|
||||
{
|
||||
return $this->getValue('twitter');
|
||||
}
|
||||
|
||||
public function hasLinks()
|
||||
{
|
||||
return $this->hasValue('links') && !empty($this->getValue('links'));
|
||||
}
|
||||
|
||||
public function getLinks()
|
||||
{
|
||||
return $this->getValue('links');
|
||||
}
|
||||
|
||||
public function hasRepository()
|
||||
{
|
||||
return $this->hasValue('repo') && !empty($this->getValue('repo'));
|
||||
}
|
||||
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->getValue('repo');
|
||||
}
|
||||
|
||||
public function hasButtons()
|
||||
{
|
||||
return $this->hasValue('buttons') && !empty($this->getValue('buttons'));
|
||||
}
|
||||
|
||||
public function getButtons()
|
||||
{
|
||||
return $this->getValue('buttons');
|
||||
}
|
||||
|
||||
public function hasLandingPage()
|
||||
{
|
||||
if ($this->hasValue('auto_landing')) {
|
||||
return $this->getValue('auto_landing');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasBreadcrumbs()
|
||||
{
|
||||
if ($this->hasValue('breadcrumbs')) {
|
||||
return $this->getValue('breadcrumbs');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getBreadcrumbsSeparator()
|
||||
{
|
||||
return $this->getValue('breadcrumb_separator');
|
||||
}
|
||||
|
||||
public function getTheme()
|
||||
{
|
||||
return $this->getValue('theme');
|
||||
}
|
||||
|
||||
public function hasThemeVariant()
|
||||
{
|
||||
return $this->hasValue('theme-variant') && !empty($this->getValue('theme-variant'));
|
||||
}
|
||||
|
||||
public function getThemeVariant()
|
||||
{
|
||||
return $this->getValue('theme-variant');
|
||||
}
|
||||
}
|
||||
|
@ -4,27 +4,34 @@ use Todaymade\Daux\Tree\Root;
|
||||
|
||||
class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
{
|
||||
/**
|
||||
* @var Template
|
||||
*/
|
||||
public $templateRenderer;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $language;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $homepage;
|
||||
|
||||
private function isHomepage()
|
||||
private function isHomepage(): bool
|
||||
{
|
||||
// If the current page isn't the index, no chance it is the landing page
|
||||
if ($this->file->getParent()->getIndexPage() != $this->file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the direct parent is root, this is the homage
|
||||
// If the direct parent is root, this is the homepage
|
||||
return $this->file->getParent() instanceof Root;
|
||||
}
|
||||
|
||||
private function isLanding() {
|
||||
// If we don't have the auto_landing parameter, we don't want any homepage
|
||||
if (array_key_exists('auto_landing', $this->params['html']) && !$this->params['html']['auto_landing']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->homepage;
|
||||
private function isLanding(): bool
|
||||
{
|
||||
return $this->config->getHTML()->hasLandingPage() && $this->homepage;
|
||||
}
|
||||
|
||||
private function initialize()
|
||||
@ -32,7 +39,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
$this->homepage = $this->isHomepage();
|
||||
|
||||
$this->language = '';
|
||||
if ($this->params->isMultilanguage() && count($this->file->getParents())) {
|
||||
if ($this->config->isMultilanguage() && count($this->file->getParents())) {
|
||||
$language_dir = $this->file->getParents()[0];
|
||||
$this->language = $language_dir->getName();
|
||||
}
|
||||
@ -41,6 +48,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
/**
|
||||
* @param \Todaymade\Daux\Tree\Directory[] $parents
|
||||
* @param bool $multilanguage
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBreadcrumbTrail($parents, $multilanguage)
|
||||
@ -62,16 +70,16 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
protected function generatePage()
|
||||
{
|
||||
$this->initialize();
|
||||
$params = $this->params;
|
||||
$config = $this->config;
|
||||
|
||||
$entry_page = [];
|
||||
if ($this->homepage) {
|
||||
if ($params->isMultilanguage()) {
|
||||
foreach ($params['languages'] as $key => $name) {
|
||||
$entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
|
||||
if ($config->isMultilanguage()) {
|
||||
foreach ($config->getLanguages() as $key => $name) {
|
||||
$entry_page[$name] = $config->getBasePage() . $config->getEntryPage()[$key]->getUrl();
|
||||
}
|
||||
} else {
|
||||
$entry_page['__VIEW_DOCUMENTATION__'] = $params['base_page'] . $params['entry_page']->getUrl();
|
||||
$entry_page['__VIEW_DOCUMENTATION__'] = $config->getBasePage() . $config->getEntryPage()->getUrl();
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,32 +93,32 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
'relative_path' => $this->file->getRelativePath(),
|
||||
'modified_time' => filemtime($this->file->getPath()),
|
||||
'markdown' => $this->content,
|
||||
'request' => $params['request'],
|
||||
'request' => $config->getRequest(),
|
||||
'content' => $this->getPureContent(),
|
||||
'breadcrumbs' => $params['html']['breadcrumbs'],
|
||||
'breadcrumbs' => $config->getHTML()->hasBreadcrumbs(),
|
||||
'prev' => $this->file->getPrevious(),
|
||||
'next' => $this->file->getNext(),
|
||||
'attributes' => $this->file->getAttribute()
|
||||
'attributes' => $this->file->getAttribute(),
|
||||
];
|
||||
|
||||
if ($page['breadcrumbs']) {
|
||||
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params->isMultilanguage());
|
||||
$page['breadcrumb_separator'] = $params['html']['breadcrumb_separator'];
|
||||
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $config->isMultilanguage());
|
||||
$page['breadcrumb_separator'] = $this->config->getHTML()->getBreadcrumbsSeparator();
|
||||
|
||||
if ($this->homepage) {
|
||||
$page['breadcrumb_trail'] = [['title' => $this->file->getTitle(), 'url' => '']];
|
||||
}
|
||||
}
|
||||
|
||||
$context = ['page' => $page, 'params' => $params];
|
||||
$context = ['page' => $page, 'config' => $config];
|
||||
|
||||
$template = "theme::content";
|
||||
$template = 'theme::content';
|
||||
if ($this->isLanding()) {
|
||||
$template = "theme::home";
|
||||
$template = 'theme::home';
|
||||
}
|
||||
|
||||
if (array_key_exists('template', $page['attributes'])) {
|
||||
$template = "theme::" . $page['attributes']['template'];
|
||||
$template = 'theme::' . $page['attributes']['template'];
|
||||
}
|
||||
|
||||
return $this->templateRenderer->render($template, $context);
|
||||
|
@ -1,7 +1,11 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML\ContentTypes\Markdown;
|
||||
|
||||
use League\CommonMark\Block\Element as BlockElement;
|
||||
use League\CommonMark\Environment;
|
||||
use League\CommonMark\Event\DocumentParsedEvent;
|
||||
use League\CommonMark\Inline\Element as InlineElement;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||
|
||||
class CommonMarkConverter extends \Todaymade\Daux\ContentTypes\Markdown\CommonMarkConverter
|
||||
{
|
||||
@ -9,9 +13,12 @@ class CommonMarkConverter extends \Todaymade\Daux\ContentTypes\Markdown\CommonMa
|
||||
{
|
||||
parent::extendEnvironment($environment, $config);
|
||||
|
||||
$environment->addBlockRenderer('FencedCode', new FencedCodeRenderer());
|
||||
$environment->addBlockRenderer(BlockElement\FencedCode::class, new FencedCodeRenderer());
|
||||
|
||||
$environment->addDocumentProcessor(new TOC\Processor($config));
|
||||
$environment->addBlockRenderer('Todaymade\Daux\ContentTypes\Markdown\TableOfContents', new TOC\Renderer($config));
|
||||
$processor = new TOC\Processor($config);
|
||||
$environment->addEventListener(DocumentParsedEvent::class, [$processor, 'onDocumentParsed']);
|
||||
$environment->addBlockRenderer(TableOfContents::class, new TOC\Renderer($config));
|
||||
|
||||
$environment->addInlineRenderer(InlineElement\Image::class, new ImageRenderer($config));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML\ContentTypes\Markdown;
|
||||
|
||||
use Todaymade\Daux\Config;
|
||||
|
||||
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
||||
{
|
||||
public function __construct(Config $config)
|
||||
protected function createConverter()
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
||||
return new CommonMarkConverter(['daux' => $this->config]);
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,17 @@ use League\CommonMark\Util\Xml;
|
||||
|
||||
class FencedCodeRenderer implements BlockRendererInterface
|
||||
{
|
||||
function __construct() {
|
||||
/**
|
||||
* @var Highlighter
|
||||
*/
|
||||
private $hl;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->hl = new Highlighter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractBlock $block
|
||||
* @param HtmlRendererInterface $htmlRenderer
|
||||
* @param bool $inTightList
|
||||
*
|
||||
* @return HtmlElement|string
|
||||
@ -43,7 +47,7 @@ class FencedCodeRenderer implements BlockRendererInterface
|
||||
$highlighted = $this->hl->highlight($language, $content);
|
||||
$content = $highlighted->value;
|
||||
$attrs['class'] .= 'hljs ' . $highlighted->language;
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$attrs['class'] .= 'language-' . $language;
|
||||
}
|
||||
}
|
||||
@ -65,6 +69,6 @@ class FencedCodeRenderer implements BlockRendererInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
return Xml::escape($infoWords[0], true);
|
||||
return Xml::escape($infoWords[0]);
|
||||
}
|
||||
}
|
||||
|
95
libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php
Normal file
95
libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML\ContentTypes\Markdown;
|
||||
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
use League\CommonMark\Inline\Element\AbstractInline;
|
||||
use League\CommonMark\Inline\Element\Image;
|
||||
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
|
||||
use League\CommonMark\Util\ConfigurationAwareInterface;
|
||||
use League\CommonMark\Util\ConfigurationInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||
|
||||
class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $daux;
|
||||
|
||||
/**
|
||||
* @var ConfigurationInterface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \League\CommonMark\Inline\Renderer\ImageRenderer
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
public function __construct($daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
$this->parent = new \League\CommonMark\Inline\Renderer\ImageRenderer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative URLs can be done using either the folder with
|
||||
* number prefix or the final name (with prefix stripped).
|
||||
* This ensures that we always use the final name when generating.
|
||||
*
|
||||
* @param mixed $url
|
||||
*
|
||||
* @throws LinkNotFoundException
|
||||
*/
|
||||
protected function getCleanUrl($url)
|
||||
{
|
||||
// empty urls and anchors should
|
||||
// not go through the url resolver
|
||||
if (!DauxHelper::isValidUrl($url)) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
// Absolute urls, shouldn't either
|
||||
if (DauxHelper::isExternalUrl($url)) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
try {
|
||||
$file = DauxHelper::resolveInternalFile($this->daux, $url);
|
||||
|
||||
return DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl());
|
||||
} catch (LinkNotFoundException $e) {
|
||||
if ($this->daux->isStatic()) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Image $inline
|
||||
*
|
||||
* @throws LinkNotFoundException
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
if (!($inline instanceof Image)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
$inline->setUrl($this->getCleanUrl($inline->getUrl()));
|
||||
|
||||
return $this->parent->render($inline, $htmlRenderer);
|
||||
}
|
||||
|
||||
public function setConfiguration(ConfigurationInterface $configuration)
|
||||
{
|
||||
$this->config = $configuration;
|
||||
$this->parent->setConfiguration($configuration);
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ class Entry
|
||||
{
|
||||
protected $content;
|
||||
protected $level;
|
||||
protected $parent = null;
|
||||
protected $parent;
|
||||
protected $children = [];
|
||||
|
||||
public function __construct(Heading $content)
|
||||
@ -56,7 +56,6 @@ class Entry
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entry $parent
|
||||
* @param bool $addChild
|
||||
*/
|
||||
public function setParent(Entry $parent, $addChild = true)
|
||||
@ -67,9 +66,6 @@ class Entry
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entry $child
|
||||
*/
|
||||
public function addChild(Entry $child)
|
||||
{
|
||||
$child->setParent($this, false);
|
||||
|
@ -7,16 +7,20 @@ use League\CommonMark\Block\Element\ListBlock;
|
||||
use League\CommonMark\Block\Element\ListData;
|
||||
use League\CommonMark\Block\Element\ListItem;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\DocumentProcessorInterface;
|
||||
use League\CommonMark\Event\DocumentParsedEvent;
|
||||
use League\CommonMark\Inline\Element\Link;
|
||||
use League\CommonMark\Inline\Element\Text;
|
||||
use League\CommonMark\Node\Node;
|
||||
use ReflectionMethod;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
|
||||
class Processor implements DocumentProcessorInterface
|
||||
class Processor
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
public function __construct(Config $config)
|
||||
@ -24,18 +28,9 @@ class Processor implements DocumentProcessorInterface
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function hasAutoTOC()
|
||||
{
|
||||
return array_key_exists('html', $this->config) && array_key_exists('auto_toc', $this->config['html']) && $this->config['html']['auto_toc'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Document $document
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processDocument(Document $document)
|
||||
public function onDocumentParsed(DocumentParsedEvent $event)
|
||||
{
|
||||
$document = $event->getDocument();
|
||||
/** @var TableOfContents[] $tocs */
|
||||
$tocs = [];
|
||||
|
||||
@ -48,6 +43,7 @@ class Processor implements DocumentProcessorInterface
|
||||
|
||||
if ($node instanceof TableOfContents && !$event->isEntering()) {
|
||||
$tocs[] = $node;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -59,7 +55,7 @@ class Processor implements DocumentProcessorInterface
|
||||
$headings[] = new Entry($node);
|
||||
}
|
||||
|
||||
if (count($headings) && (count($tocs) || $this->hasAutoTOC())) {
|
||||
if (count($headings) && (count($tocs) || $this->config->getHTML()->hasAutomaticTableOfContents())) {
|
||||
$generated = $this->generate($headings);
|
||||
|
||||
if (count($tocs)) {
|
||||
@ -72,43 +68,27 @@ class Processor implements DocumentProcessorInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an escaped version of the link
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
protected function escaped($url) {
|
||||
$url = trim($url);
|
||||
$url = preg_replace('~[^\\pL0-9_]+~u', '-', $url);
|
||||
$url = trim($url, "-");
|
||||
$url = iconv("utf-8", "ASCII//TRANSLIT//IGNORE", $url);
|
||||
$url = preg_replace('~[^-a-zA-Z0-9_]+~', '', $url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
protected function getUniqueId(Document $document, $proposed) {
|
||||
if ($proposed == "page_") {
|
||||
$proposed = "page_section_" . (count($document->heading_ids) + 1);
|
||||
protected function getUniqueId(Document $document, $proposed)
|
||||
{
|
||||
if ($proposed == 'page_') {
|
||||
$proposed = 'page_section_' . (count($document->heading_ids) + 1);
|
||||
}
|
||||
|
||||
// Quick path, it's a unique ID
|
||||
if (!in_array($proposed, $document->heading_ids)) {
|
||||
$document->heading_ids[] = $proposed;
|
||||
|
||||
return $proposed;
|
||||
}
|
||||
|
||||
$extension = 1; // Initialize the variable at one, so on the first iteration we have 2
|
||||
do {
|
||||
$extension++;
|
||||
++$extension;
|
||||
} while (in_array("$proposed-$extension", $document->heading_ids));
|
||||
|
||||
return "$proposed-$extension";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Heading $node
|
||||
*/
|
||||
protected function ensureHeadingHasId(Document $document, Heading $node)
|
||||
{
|
||||
// If the node has an ID, no need to generate it, just check it's unique
|
||||
@ -139,13 +119,14 @@ class Processor implements DocumentProcessorInterface
|
||||
}
|
||||
}
|
||||
|
||||
$node->data['attributes']['id'] = $this->getUniqueId($document,'page_'. $this->escaped($text));
|
||||
$node->data['attributes']['id'] = $this->getUniqueId($document, 'page_' . DauxHelper::slug($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a tree of the list of headings
|
||||
* Make a tree of the list of headings.
|
||||
*
|
||||
* @param Entry[] $headings
|
||||
*
|
||||
* @return RootEntry
|
||||
*/
|
||||
public function generate($headings)
|
||||
@ -161,19 +142,21 @@ class Processor implements DocumentProcessorInterface
|
||||
|
||||
$parent->addChild($heading);
|
||||
$previous = $heading;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if ($heading->getLevel() > $previous->getLevel()) {
|
||||
$previous->addChild($heading);
|
||||
$previous = $heading;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//if ($heading->getLevel() == $previous->getLevel()) {
|
||||
$previous->getParent()->addChild($heading);
|
||||
$previous = $heading;
|
||||
|
||||
continue;
|
||||
//}
|
||||
}
|
||||
@ -183,6 +166,7 @@ class Processor implements DocumentProcessorInterface
|
||||
|
||||
/**
|
||||
* @param Entry[] $entries
|
||||
*
|
||||
* @return ListBlock
|
||||
*/
|
||||
protected function render(array $entries)
|
||||
@ -234,7 +218,6 @@ class Processor implements DocumentProcessorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Heading $node
|
||||
* @return Node[]
|
||||
*/
|
||||
protected function cloneChildren(Heading $node)
|
||||
|
@ -4,9 +4,15 @@ use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||
|
||||
class Renderer implements BlockRendererInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
@ -14,7 +20,12 @@ class Renderer implements BlockRendererInterface
|
||||
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof TableOfContents)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
$content = $htmlRenderer->renderBlocks($block->children());
|
||||
|
||||
return $this->config->templateRenderer
|
||||
->getEngine($this->config)
|
||||
->render('theme::partials/table_of_contents', ['content' => $content]);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\Config as GlobalConfig;
|
||||
use Todaymade\Daux\Console\RunAction;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
@ -16,23 +16,24 @@ use Todaymade\Daux\Tree\Raw;
|
||||
|
||||
class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
{
|
||||
use RunAction, HTMLUtils;
|
||||
use RunAction;
|
||||
use HTMLUtils;
|
||||
|
||||
/** @var Daux */
|
||||
protected $daux;
|
||||
|
||||
/** @var Template */
|
||||
protected $templateRenderer;
|
||||
|
||||
protected $indexed_pages = [];
|
||||
|
||||
/**
|
||||
* @param Daux $daux
|
||||
*/
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$params = $daux->getParams();
|
||||
$config = $daux->getConfig();
|
||||
|
||||
$this->daux = $daux;
|
||||
$this->templateRenderer = new Template($params);
|
||||
$params->templateRenderer = $this->templateRenderer;
|
||||
$this->templateRenderer = new Template($config);
|
||||
$config->templateRenderer = $this->templateRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,7 +42,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
public function getContentTypes()
|
||||
{
|
||||
return [
|
||||
'markdown' => new ContentType($this->daux->getParams()),
|
||||
'markdown' => new ContentType($this->daux->getConfig()),
|
||||
];
|
||||
}
|
||||
|
||||
@ -49,38 +50,34 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
{
|
||||
$destination = $input->getOption('destination');
|
||||
|
||||
$params = $this->daux->getParams();
|
||||
$config = $this->daux->getConfig();
|
||||
if (is_null($destination)) {
|
||||
$destination = $this->daux->local_base . DIRECTORY_SEPARATOR . 'static';
|
||||
$destination = $config->getLocalBase() . DIRECTORY_SEPARATOR . 'static';
|
||||
}
|
||||
|
||||
$this->runAction(
|
||||
'Copying Static assets ...',
|
||||
$width,
|
||||
function() use ($destination, $params) {
|
||||
function () use ($destination, $config) {
|
||||
$this->ensureEmptyDestination($destination);
|
||||
|
||||
$this->copyThemes($destination, $params->getThemesPath());
|
||||
$this->copyThemes($destination, $config->getThemesPath());
|
||||
}
|
||||
);
|
||||
|
||||
$output->writeLn('Generating ...');
|
||||
|
||||
if (!array_key_exists('search', $params['html']) || !$params['html']['search']) {
|
||||
$params['html']['search'] = $input->getOption('search');
|
||||
}
|
||||
|
||||
$this->generateRecursive($this->daux->tree, $destination, $params, $output, $width, $params['html']['search']);
|
||||
$this->generateRecursive($this->daux->tree, $destination, $config, $output, $width, $config->getHTML()->hasSearch());
|
||||
|
||||
GeneratorHelper::copyRecursive(
|
||||
$this->daux->local_base . DIRECTORY_SEPARATOR . 'daux_libraries' . DIRECTORY_SEPARATOR,
|
||||
$config->getLocalBase() . DIRECTORY_SEPARATOR . 'daux_libraries' . DIRECTORY_SEPARATOR,
|
||||
$destination . DIRECTORY_SEPARATOR . 'daux_libraries'
|
||||
);
|
||||
|
||||
if ($params['html']['search']) {
|
||||
if ($config->getHTML()->hasSearch()) {
|
||||
file_put_contents(
|
||||
$destination . DIRECTORY_SEPARATOR . 'daux_search_index.json',
|
||||
json_encode(['pages' => $this->indexed_pages])
|
||||
$destination . DIRECTORY_SEPARATOR . 'daux_search_index.js',
|
||||
'load_search_index(' . json_encode(['pages' => $this->indexed_pages]) . ');'
|
||||
);
|
||||
|
||||
if (json_last_error()) {
|
||||
@ -94,9 +91,10 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
* script code, and embedded objects. Add line breaks around
|
||||
* block-level tags to prevent word joining after tag removal.
|
||||
* Also collapse whitespace to single space and trim result.
|
||||
* modified from: http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page
|
||||
* modified from: http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function sanitize($text)
|
||||
@ -134,44 +132,41 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
|
||||
// Sometimes strings are detected as invalid UTF-8 and json_encode can't treat them
|
||||
// iconv can fix those strings
|
||||
$text = iconv('UTF-8', 'UTF-8//IGNORE', $text);
|
||||
|
||||
return $text;
|
||||
return iconv('UTF-8', 'UTF-8//IGNORE', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively generate the documentation
|
||||
* Recursively generate the documentation.
|
||||
*
|
||||
* @param Directory $tree
|
||||
* @param string $output_dir
|
||||
* @param \Todaymade\Daux\Config $params
|
||||
* @param OutputInterface $output
|
||||
* @param int $width
|
||||
* @param bool $index_pages
|
||||
* @param string $base_url
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function generateRecursive(Directory $tree, $output_dir, $params, $output, $width, $index_pages, $base_url = '')
|
||||
private function generateRecursive(Directory $tree, $output_dir, GlobalConfig $config, $output, $width, $index_pages, $base_url = '')
|
||||
{
|
||||
DauxHelper::rebaseConfiguration($params, $base_url);
|
||||
DauxHelper::rebaseConfiguration($config, $base_url);
|
||||
|
||||
if ($base_url !== '' && empty($params['entry_page'])) {
|
||||
$params['entry_page'] = $tree->getFirstPage();
|
||||
if ($base_url !== '' && !$config->hasEntryPage()) {
|
||||
$config->setEntryPage($tree->getFirstPage());
|
||||
}
|
||||
|
||||
foreach ($tree->getEntries() as $key => $node) {
|
||||
if ($node instanceof Directory) {
|
||||
$new_output_dir = $output_dir . DIRECTORY_SEPARATOR . $key;
|
||||
mkdir($new_output_dir);
|
||||
$this->generateRecursive($node, $new_output_dir, $params, $output, $width, $index_pages, '../' . $base_url);
|
||||
$this->generateRecursive($node, $new_output_dir, $config, $output, $width, $index_pages, '../' . $base_url);
|
||||
|
||||
// Rebase configuration again as $params is a shared object
|
||||
DauxHelper::rebaseConfiguration($params, $base_url);
|
||||
// Rebase configuration again as $config is a shared object
|
||||
DauxHelper::rebaseConfiguration($config, $base_url);
|
||||
} else {
|
||||
$this->runAction(
|
||||
'- ' . $node->getUrl(),
|
||||
$width,
|
||||
function() use ($node, $output_dir, $key, $params, $index_pages) {
|
||||
function () use ($node, $output_dir, $key, $config, $index_pages) {
|
||||
if ($node instanceof Raw) {
|
||||
copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key);
|
||||
|
||||
@ -180,13 +175,13 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
|
||||
$this->daux->tree->setActiveNode($node);
|
||||
|
||||
$generated = $this->generateOne($node, $params);
|
||||
$generated = $this->generateOne($node, $config);
|
||||
file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent());
|
||||
if ($index_pages) {
|
||||
$this->indexed_pages[] = [
|
||||
'title' => $node->getTitle(),
|
||||
'text' => $this->sanitize($generated->getPureContent()),
|
||||
'tags' => '',
|
||||
'tags' => '',
|
||||
'url' => $node->getUrl(),
|
||||
];
|
||||
}
|
||||
@ -197,11 +192,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entry $node
|
||||
* @param Config $params
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
*/
|
||||
public function generateOne(Entry $node, Config $params)
|
||||
public function generateOne(Entry $node, GlobalConfig $config)
|
||||
{
|
||||
if ($node instanceof Raw) {
|
||||
return new RawPage($node->getPath());
|
||||
@ -211,9 +204,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
return new ComputedRawPage($node);
|
||||
}
|
||||
|
||||
$params['request'] = $node->getUrl();
|
||||
$config->setRequest($node->getUrl());
|
||||
|
||||
$contentPage = ContentPage::fromFile($node, $params, $this->daux->getContentTypeHandler()->getType($node));
|
||||
$contentPage = ContentPage::fromFile($node, $config, $this->daux->getContentTypeHandler()->getType($node));
|
||||
$contentPage->templateRenderer = $this->templateRenderer;
|
||||
|
||||
return $contentPage;
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
use Todaymade\Daux\GeneratorHelper;
|
||||
|
||||
trait HTMLUtils {
|
||||
trait HTMLUtils
|
||||
{
|
||||
public function ensureEmptyDestination($destination)
|
||||
{
|
||||
if (is_dir($destination)) {
|
||||
@ -13,7 +14,7 @@ trait HTMLUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all files from $local to $destination
|
||||
* Copy all files from $local to $destination.
|
||||
*
|
||||
* @param string $destination
|
||||
* @param string $local_base
|
||||
|
@ -4,7 +4,7 @@ namespace Todaymade\Daux\Format\HTML;
|
||||
|
||||
use League\Plates\Engine;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\Config as GlobalConfig;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
@ -13,25 +13,25 @@ class Template
|
||||
{
|
||||
protected $engine;
|
||||
|
||||
protected $params;
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @param string $base
|
||||
* @param string $theme
|
||||
*/
|
||||
public function __construct(Config $params)
|
||||
public function __construct(GlobalConfig $config)
|
||||
{
|
||||
$this->params = $params;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getEngine(Config $params)
|
||||
public function getEngine(GlobalConfig $config)
|
||||
{
|
||||
if ($this->engine) {
|
||||
return $this->engine;
|
||||
}
|
||||
|
||||
$base = $params['templates'];
|
||||
$theme = $params['theme']['templates'];
|
||||
$base = $config->getTemplates();
|
||||
$theme = $config->getTheme()->getTemplates();
|
||||
|
||||
// Use internal templates if no templates
|
||||
// dir exists in the working directory
|
||||
@ -55,19 +55,20 @@ class Template
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($name, array $data = [])
|
||||
{
|
||||
$engine = $this->getEngine($data['params']);
|
||||
$engine = $this->getEngine($data['config']);
|
||||
|
||||
$engine->addData([
|
||||
'base_url' => $data['params']['base_url'],
|
||||
'base_page' => $data['params']['base_page'],
|
||||
'base_url' => $data['config']->getBaseUrl(),
|
||||
'base_page' => $data['config']->getBasePage(),
|
||||
'page' => $data['page'],
|
||||
'params' => $data['params'],
|
||||
'tree' => $data['params']['tree'],
|
||||
'params' => $data['config'], // legacy name for config
|
||||
'config' => $data['config'],
|
||||
'tree' => $data['config']['tree'],
|
||||
]);
|
||||
|
||||
Daux::writeln("Rendering template '$name'", OutputInterface::VERBOSITY_VERBOSE);
|
||||
@ -84,7 +85,7 @@ class Template
|
||||
});
|
||||
|
||||
$engine->registerFunction('translate', function ($key) {
|
||||
$language = $this->params['language'];
|
||||
$language = $this->config->getLanguage();
|
||||
|
||||
if (isset($this->engine->getData('page')['page'])) {
|
||||
$page = $this->engine->getData('page');
|
||||
@ -93,14 +94,12 @@ class Template
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($language, $this->params['strings'])) {
|
||||
if (array_key_exists($key, $this->params['strings'][$language])) {
|
||||
return $this->params['strings'][$language][$key];
|
||||
}
|
||||
if ($this->config->hasTranslationKey($language, $key)) {
|
||||
return $this->config->getTranslationKey($language, $key);
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $this->params['strings']['en'])) {
|
||||
return $this->params['strings']['en'][$key];
|
||||
if ($this->config->hasTranslationKey('en', $key)) {
|
||||
return $this->config->getTranslationKey('en', $key);
|
||||
}
|
||||
|
||||
return "Unknown key $key";
|
||||
@ -197,6 +196,7 @@ class Template
|
||||
|
||||
/**
|
||||
* @param string $separator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getSeparator($separator)
|
||||
|
31
libs/Format/HTML/Theme.php
Normal file
31
libs/Format/HTML/Theme.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML;
|
||||
|
||||
use Todaymade\Daux\BaseConfig;
|
||||
|
||||
class Theme extends BaseConfig
|
||||
{
|
||||
public function getFonts()
|
||||
{
|
||||
return $this->getValue('fonts');
|
||||
}
|
||||
|
||||
public function getCSS()
|
||||
{
|
||||
return $this->getValue('css');
|
||||
}
|
||||
|
||||
public function getJS()
|
||||
{
|
||||
return $this->getValue('js');
|
||||
}
|
||||
|
||||
public function getFavicon()
|
||||
{
|
||||
return $this->getValue('favicon');
|
||||
}
|
||||
|
||||
public function getTemplates()
|
||||
{
|
||||
return $this->getValue('templates');
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTMLFile;
|
||||
|
||||
use RuntimeException;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
|
||||
@ -24,7 +23,7 @@ class Book
|
||||
|
||||
protected function getPageUrl($page)
|
||||
{
|
||||
return "file_" . str_replace('/', '_', $page->getUrl());
|
||||
return 'file_' . str_replace('/', '_', $page->getUrl());
|
||||
}
|
||||
|
||||
protected function buildNavigation(Directory $tree)
|
||||
@ -38,7 +37,7 @@ class Book
|
||||
|
||||
$nav[] = [
|
||||
'title' => $node->getTitle(),
|
||||
'href' => "#" . $this->getPageUrl($node),
|
||||
'href' => '#' . $this->getPageUrl($node),
|
||||
];
|
||||
} elseif ($node instanceof Directory) {
|
||||
if (!$node->hasContent()) {
|
||||
@ -49,7 +48,7 @@ class Book
|
||||
|
||||
$nav[] = [
|
||||
'title' => $node->getTitle(),
|
||||
'href' => "#" . $this->getPageUrl($page_index),
|
||||
'href' => '#' . $this->getPageUrl($page_index),
|
||||
'children' => $this->buildNavigation($node),
|
||||
];
|
||||
}
|
||||
@ -89,7 +88,7 @@ class Book
|
||||
|
||||
protected function generateCover()
|
||||
{
|
||||
return "<div>" .
|
||||
return '<div>' .
|
||||
"<h1 style='font-size:40pt; margin-bottom:0;'>{$this->cover['title']}</h1>" .
|
||||
"<p><strong>{$this->cover['subject']}</strong> by {$this->cover['author']}</p>" .
|
||||
'</div><div class="PageBreak"> </div>';
|
||||
|
@ -11,23 +11,23 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
{
|
||||
$content = parent::generatePage();
|
||||
|
||||
//Embed images
|
||||
// Embed images
|
||||
// We do it after generation so we can catch the images that were in html already
|
||||
$content = (new EmbedImages($this->params['tree']))
|
||||
return (new EmbedImages($this->config->getTree()))
|
||||
->embed(
|
||||
$content,
|
||||
$this->file,
|
||||
function($src, array $attributes, Raw $file) {
|
||||
$content = base64_encode(file_get_contents($file->getPath()));
|
||||
function ($src, array $attributes, Raw $file) {
|
||||
// TODO :: ignore absolute paths
|
||||
$content = base64_encode(file_get_contents($file->getPath()));
|
||||
$attr = '';
|
||||
foreach ($attributes as $name => $value) {
|
||||
$attr .= ' ' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';
|
||||
}
|
||||
|
||||
// TODO :: handle other formats than PNG as well
|
||||
return "<img $attr src=\"data:image/png;base64,$content\"/>";
|
||||
}
|
||||
);
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTMLFile\ContentTypes\Markdown;
|
||||
|
||||
use League\CommonMark\Environment;
|
||||
use Todaymade\Daux\Config;
|
||||
|
||||
class CommonMarkConverter extends \Todaymade\Daux\Format\HTML\ContentTypes\Markdown\CommonMarkConverter
|
||||
{
|
||||
protected function getLinkRenderer(Environment $environment)
|
||||
{
|
||||
var_dump(LinkRenderer::class);
|
||||
return new LinkRenderer($environment->getConfig('daux'));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTMLFile\ContentTypes\Markdown;
|
||||
|
||||
use Todaymade\Daux\Config;
|
||||
|
||||
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
||||
{
|
||||
public function __construct(Config $config)
|
||||
protected function createConverter()
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
||||
return new CommonMarkConverter(['daux' => $this->config]);
|
||||
}
|
||||
}
|
||||
|
@ -4,30 +4,22 @@ use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
use League\CommonMark\Inline\Element\AbstractInline;
|
||||
use League\CommonMark\Inline\Element\Link;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
|
||||
class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
{
|
||||
/**
|
||||
* @param AbstractInline|Link $inline
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @return HtmlElement
|
||||
*
|
||||
* @throws LinkNotFoundException
|
||||
*
|
||||
* @return HtmlElement
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
// This can't be in the method type as
|
||||
// the method is an abstract and should
|
||||
// have the same interface
|
||||
if (!$inline instanceof Link) {
|
||||
throw new \RuntimeException(
|
||||
'Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ .
|
||||
" the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" .
|
||||
get_class($inline) . "' was provided"
|
||||
);
|
||||
if (!($inline instanceof Link)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
$element = parent::render($inline, $htmlRenderer);
|
||||
@ -36,12 +28,12 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
|
||||
// empty urls and anchors should
|
||||
// not go through the url resolver
|
||||
if (!$this->isValidUrl($url)) {
|
||||
if (!DauxHelper::isValidUrl($url)) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
// Absolute urls, shouldn't either
|
||||
if ($this->isExternalUrl($url)) {
|
||||
if (DauxHelper::isExternalUrl($url)) {
|
||||
$element->setAttribute('class', 'Link--external');
|
||||
|
||||
return $element;
|
||||
@ -56,7 +48,7 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
}
|
||||
|
||||
try {
|
||||
$file = $this->resolveInternalFile($url);
|
||||
$file = DauxHelper::resolveInternalFile($this->daux, $url);
|
||||
$url = $file->getUrl();
|
||||
} catch (LinkNotFoundException $e) {
|
||||
if ($this->daux->isStatic()) {
|
||||
|
@ -4,27 +4,28 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Console\RunAction;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\Format\HTML\Template;
|
||||
use Todaymade\Daux\Format\HTML\HTMLUtils;
|
||||
use Todaymade\Daux\Format\HTML\Template;
|
||||
use Todaymade\Daux\Format\HTMLFile\ContentTypes\Markdown\ContentType;
|
||||
|
||||
class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
{
|
||||
use RunAction, HTMLUtils;
|
||||
use RunAction;
|
||||
use HTMLUtils;
|
||||
|
||||
/** @var Daux */
|
||||
protected $daux;
|
||||
|
||||
/**
|
||||
* @param Daux $daux
|
||||
*/
|
||||
/** @var Template */
|
||||
protected $templateRenderer;
|
||||
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$params = $daux->getParams();
|
||||
$config = $daux->getConfig();
|
||||
|
||||
$this->daux = $daux;
|
||||
$this->templateRenderer = new Template($params);
|
||||
$params->templateRenderer = $this->templateRenderer;
|
||||
$this->templateRenderer = new Template($config);
|
||||
$config->templateRenderer = $this->templateRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,7 +34,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
public function getContentTypes()
|
||||
{
|
||||
return [
|
||||
'markdown' => new ContentType($this->daux->getParams()),
|
||||
'markdown' => new ContentType($this->daux->getConfig()),
|
||||
];
|
||||
}
|
||||
|
||||
@ -44,23 +45,23 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
{
|
||||
$destination = $input->getOption('destination');
|
||||
|
||||
$params = $this->daux->getParams();
|
||||
$config = $this->daux->getConfig();
|
||||
if (is_null($destination)) {
|
||||
$destination = $this->daux->local_base . DIRECTORY_SEPARATOR . 'static';
|
||||
$destination = $config->getLocalBase() . DIRECTORY_SEPARATOR . 'static';
|
||||
}
|
||||
|
||||
$this->runAction(
|
||||
'Cleaning destination folder ...',
|
||||
$width,
|
||||
function() use ($destination, $params) {
|
||||
function () use ($destination) {
|
||||
$this->ensureEmptyDestination($destination);
|
||||
}
|
||||
);
|
||||
|
||||
$data = [
|
||||
'author' => $params['author'],
|
||||
'title' => $params['title'],
|
||||
'subject' => $params['tagline']
|
||||
'author' => $config->getAuthor(),
|
||||
'title' => $config->getTitle(),
|
||||
'subject' => $config->getTagline(),
|
||||
];
|
||||
|
||||
$book = new Book($this->daux->tree, $data);
|
||||
@ -70,9 +71,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
$this->runAction(
|
||||
'Generating ' . $current->getTitle(),
|
||||
$width,
|
||||
function () use ($book, $current, $params) {
|
||||
function () use ($book, $current, $config) {
|
||||
$contentType = $this->daux->getContentTypeHandler()->getType($current);
|
||||
$content = ContentPage::fromFile($current, $params, $contentType);
|
||||
$content = ContentPage::fromFile($current, $config, $contentType);
|
||||
$content->templateRenderer = $this->templateRenderer;
|
||||
$content = $content->getContent();
|
||||
$book->addPage($current, $content);
|
||||
|
@ -4,13 +4,14 @@ use IntlDateFormatter;
|
||||
|
||||
class FormatDate
|
||||
{
|
||||
public static function format($params, $date) {
|
||||
$locale = $params['language'];
|
||||
public static function format($config, $date)
|
||||
{
|
||||
$locale = $config->getLanguage();
|
||||
$datetype = IntlDateFormatter::LONG;
|
||||
$timetype = IntlDateFormatter::SHORT;
|
||||
$timezone = null;
|
||||
|
||||
if (!extension_loaded("intl")) {
|
||||
if (!extension_loaded('intl')) {
|
||||
$locale = 'en';
|
||||
$timezone = 'GMT';
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use RuntimeException;
|
||||
class GeneratorHelper
|
||||
{
|
||||
/**
|
||||
* Remove a directory recursively
|
||||
* Remove a directory recursively.
|
||||
*
|
||||
* @param string $dir
|
||||
*/
|
||||
@ -26,7 +26,7 @@ class GeneratorHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy files recursively
|
||||
* Copy files recursively.
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $destination
|
||||
@ -39,7 +39,7 @@ class GeneratorHelper
|
||||
|
||||
$dir = opendir($source);
|
||||
|
||||
if (!$dir) {
|
||||
if ($dir === false) {
|
||||
throw new RuntimeException("Cannot copy '$source' to '$destination'");
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,6 @@ class Processor
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* @param Daux $daux
|
||||
* @param OutputInterface $output
|
||||
* @param int $width
|
||||
*/
|
||||
public function __construct(Daux $daux, OutputInterface $output, $width)
|
||||
@ -37,10 +35,8 @@ class Processor
|
||||
* With this connection point, you can transform
|
||||
* the tree as you want, move pages, modify
|
||||
* pages and even add new ones.
|
||||
*
|
||||
* @param Root $root
|
||||
*/
|
||||
public function manipulateTree(/** @scrutinizer ignore-unused */ Root $root)
|
||||
public function manipulateTree(/* @scrutinizer ignore-unused */ Root $root)
|
||||
{
|
||||
}
|
||||
|
||||
@ -48,10 +44,8 @@ class Processor
|
||||
* This connection point provides
|
||||
* a way to extend the Markdown
|
||||
* parser and renderer.
|
||||
*
|
||||
* @param Environment $environment
|
||||
*/
|
||||
public function extendCommonMarkEnvironment(/** @scrutinizer ignore-unused */ Environment $environment)
|
||||
public function extendCommonMarkEnvironment(/* @scrutinizer ignore-unused */ Environment $environment)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -12,17 +12,17 @@ class ErrorPage extends SimplePage
|
||||
/**
|
||||
* @var \Todaymade\Daux\Config
|
||||
*/
|
||||
private $params;
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
* @param \Todaymade\Daux\Config $params
|
||||
* @param \Todaymade\Daux\Config $config
|
||||
*/
|
||||
public function __construct($title, $content, $params)
|
||||
public function __construct($title, $content, $config)
|
||||
{
|
||||
parent::__construct($title, $content);
|
||||
$this->params = $params;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,15 +30,15 @@ class ErrorPage extends SimplePage
|
||||
*/
|
||||
protected function generatePage()
|
||||
{
|
||||
$params = $this->params;
|
||||
$config = $this->config;
|
||||
$page = [
|
||||
'title' => $this->title,
|
||||
'content' => $this->getPureContent(),
|
||||
'language' => '',
|
||||
];
|
||||
|
||||
$template = new Template($params);
|
||||
$template = new Template($config);
|
||||
|
||||
return $template->render('error', ['page' => $page, 'params' => $params]);
|
||||
return $template->render('error', ['page' => $page, 'config' => $config]);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,12 @@
|
||||
<?php namespace Todaymade\Daux\Server;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as FileMimeTypeGuesserInterface;
|
||||
use Symfony\Component\Mime\MimeTypeGuesserInterface;
|
||||
|
||||
/**
|
||||
* Guesses the mime type using the file's extension
|
||||
* Guesses the mime type using the file's extension.
|
||||
*/
|
||||
class ExtensionMimeTypeGuesser implements FileMimeTypeGuesserInterface, MimeTypeGuesserInterface
|
||||
class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function guess($path)
|
||||
{
|
||||
$extension = pathinfo($path,PATHINFO_EXTENSION);
|
||||
|
||||
if ($extension == "css") {
|
||||
return "text/css";
|
||||
}
|
||||
|
||||
if ($extension == "js") {
|
||||
return "application/javascript";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -37,6 +20,16 @@ class ExtensionMimeTypeGuesser implements FileMimeTypeGuesserInterface, MimeType
|
||||
*/
|
||||
public function guessMimeType(string $path): ?string
|
||||
{
|
||||
return $this->guess($path);
|
||||
$extension = pathinfo($path, PATHINFO_EXTENSION);
|
||||
|
||||
if ($extension == 'css') {
|
||||
return 'text/css';
|
||||
}
|
||||
|
||||
if ($extension == 'js') {
|
||||
return 'application/javascript';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
<?php namespace Todaymade\Daux\Server;
|
||||
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
use Todaymade\Daux\ConfigBuilder;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception;
|
||||
@ -16,7 +17,7 @@ use Todaymade\Daux\Format\HTML\RawPage;
|
||||
class Server
|
||||
{
|
||||
private $daux;
|
||||
private $params;
|
||||
private $config;
|
||||
private $base_url;
|
||||
|
||||
/**
|
||||
@ -24,27 +25,38 @@ class Server
|
||||
*/
|
||||
private $request;
|
||||
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
|
||||
$this->request = Request::createFromGlobals();
|
||||
$this->base_url = $this->request->getHttpHost() . $this->request->getBaseUrl() . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Serve the documentation
|
||||
* Serve the documentation.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function serve()
|
||||
{
|
||||
$output = new NullOutput();
|
||||
$verbosity = getenv('DAUX_VERBOSITY');
|
||||
$output = new ConsoleOutput($verbosity);
|
||||
|
||||
$daux = new Daux(Daux::LIVE_MODE, $output);
|
||||
$daux->initializeConfiguration();
|
||||
$configFile = getenv('DAUX_CONFIG');
|
||||
if ($configFile) {
|
||||
$config = ConfigBuilder::fromFile($configFile);
|
||||
} else {
|
||||
$config = ConfigBuilder::withMode(Daux::LIVE_MODE)->build();
|
||||
}
|
||||
|
||||
$daux = new Daux($config, $output);
|
||||
|
||||
$class = $daux->getProcessorClass();
|
||||
if (!empty($class)) {
|
||||
$daux->setProcessor(new $class($daux, $output, 0));
|
||||
}
|
||||
|
||||
// Set this critical configuration
|
||||
// for the tree generation
|
||||
$daux->getParams()['index_key'] = 'index';
|
||||
|
||||
// Improve the tree with a processor
|
||||
$daux->generateTree();
|
||||
|
||||
@ -53,30 +65,24 @@ class Server
|
||||
try {
|
||||
$page = $server->handle();
|
||||
} catch (NotFoundException $e) {
|
||||
$page = new ErrorPage('An error occured', $e->getMessage(), $daux->getParams());
|
||||
$page = new ErrorPage('An error occured', $e->getMessage(), $daux->getConfig());
|
||||
}
|
||||
|
||||
$server->createResponse($page)->prepare($server->request)->send();
|
||||
}
|
||||
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
|
||||
$this->request = Request::createFromGlobals();
|
||||
$this->base_url = $this->request->getHttpHost() . $this->request->getBaseUrl() . "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a temporary file with the file suffix, for mime type detection.
|
||||
*
|
||||
* @param string $postfix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTemporaryFile($postfix) {
|
||||
private function getTemporaryFile($postfix)
|
||||
{
|
||||
$sysFileName = tempnam(sys_get_temp_dir(), 'daux');
|
||||
if ($sysFileName === false) {
|
||||
throw new \RuntimeException("Could not create temporary file");
|
||||
throw new \RuntimeException('Could not create temporary file');
|
||||
}
|
||||
|
||||
$newFileName = $sysFileName . $postfix;
|
||||
@ -88,15 +94,16 @@ class Server
|
||||
return $newFileName;
|
||||
}
|
||||
|
||||
throw new \RuntimeException("Could not create temporary file");
|
||||
throw new \RuntimeException('Could not create temporary file');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Page $page
|
||||
* @return Response
|
||||
*/
|
||||
public function createResponse(Page $page) {
|
||||
|
||||
public function createResponse(Page $page)
|
||||
{
|
||||
// Add a custom MimeType guesser in case the default ones are not available
|
||||
// This makes sure that at least CSS and JS work fine.
|
||||
$mimeTypes = MimeTypes::getDefault();
|
||||
$mimeTypes->registerGuesser(new ExtensionMimeTypeGuesser());
|
||||
|
||||
@ -107,6 +114,7 @@ class Server
|
||||
if ($page instanceof ComputedRawPage) {
|
||||
$file = $this->getTemporaryFile($page->getFilename());
|
||||
file_put_contents($file, $page->getContent());
|
||||
|
||||
return new BinaryFileResponse($file);
|
||||
}
|
||||
|
||||
@ -116,32 +124,26 @@ class Server
|
||||
/**
|
||||
* @return \Todaymade\Daux\Config
|
||||
*/
|
||||
public function getParams()
|
||||
public function getConfig()
|
||||
{
|
||||
$params = $this->daux->getParams();
|
||||
$config = $this->daux->getConfig();
|
||||
|
||||
DauxHelper::rebaseConfiguration($params, '//' . $this->base_url);
|
||||
$params['base_page'] = '//' . $this->base_url;
|
||||
if (!$this->daux->options['live']['clean_urls']) {
|
||||
$params['base_page'] .= 'index.php/';
|
||||
}
|
||||
DauxHelper::rebaseConfiguration($config, '//' . $this->base_url);
|
||||
|
||||
// Text search would be too slow on live server
|
||||
$params['html']['search'] = false;
|
||||
|
||||
return $params;
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
* @throws Exception
|
||||
* @throws NotFoundException
|
||||
*
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->params = $this->getParams();
|
||||
$this->config = $this->getConfig();
|
||||
|
||||
$request = substr($this->request->getRequestUri(), strlen($this->request->getBaseUrl()) + 1);
|
||||
|
||||
@ -157,27 +159,31 @@ class Server
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a request on custom themes
|
||||
* Handle a request on custom themes.
|
||||
*
|
||||
* @param string $request
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
*/
|
||||
public function serveTheme($request)
|
||||
{
|
||||
$file = $this->getParams()->getThemesPath() . $request;
|
||||
$file = $this->getConfig()->getThemesPath() . $request;
|
||||
|
||||
if (file_exists($file)) {
|
||||
return new RawPage($file);
|
||||
}
|
||||
|
||||
throw new NotFoundException;
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $request
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*
|
||||
* @return \Todaymade\Daux\Format\Base\Page
|
||||
*/
|
||||
private function getPage($request)
|
||||
{
|
||||
@ -197,6 +203,6 @@ class Server
|
||||
);
|
||||
}
|
||||
|
||||
return $this->daux->getGenerator()->generateOne($file, $this->params);
|
||||
return $this->daux->getGenerator()->generateOne($file, $this->config);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class Builder
|
||||
'.DS_Store', 'Thumbs.db',
|
||||
];
|
||||
|
||||
protected static function isIgnored(\SplFileInfo $file, $ignore)
|
||||
protected static function isIgnored(SplFileInfo $file, $ignore)
|
||||
{
|
||||
$filename = $file->getFilename();
|
||||
|
||||
@ -34,9 +34,10 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name for a file
|
||||
* Get name for a file.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getName($path)
|
||||
@ -52,14 +53,16 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the initial tree
|
||||
* Build the initial tree.
|
||||
*
|
||||
* @param Directory $node
|
||||
* @param array $ignore
|
||||
*/
|
||||
public static function build($node, $ignore)
|
||||
{
|
||||
if (($it = new \FilesystemIterator($node->getPath())) == false) {
|
||||
try {
|
||||
$it = new \FilesystemIterator($node->getPath());
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -94,8 +97,6 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Directory $parent
|
||||
* @param SplFileInfo $file
|
||||
* @return Content|Raw
|
||||
*/
|
||||
public static function createContent(Directory $parent, SplFileInfo $file)
|
||||
@ -104,7 +105,7 @@ class Builder
|
||||
|
||||
$config = $parent->getConfig();
|
||||
|
||||
if (!in_array($file->getExtension(), $config['valid_content_extensions'])) {
|
||||
if (!in_array($file->getExtension(), $config->getValidContentExtensions())) {
|
||||
$uri = $file->getFilename();
|
||||
|
||||
$entry = new Raw($parent, $uri, $file);
|
||||
@ -122,7 +123,7 @@ class Builder
|
||||
|
||||
$entry = new Content($parent, $uri, $file);
|
||||
|
||||
if ($entry->getUri() == $config['index_key']) {
|
||||
if ($entry->getUri() == $config->getIndexKey()) {
|
||||
if ($parent instanceof Root) {
|
||||
$entry->setTitle($config->getTitle());
|
||||
} else {
|
||||
@ -139,6 +140,7 @@ class Builder
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removeSortingInformations($filename)
|
||||
@ -152,8 +154,8 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Directory $parent
|
||||
* @param string $title
|
||||
*
|
||||
* @return Directory
|
||||
*/
|
||||
public static function getOrCreateDir(Directory $parent, $title)
|
||||
@ -171,8 +173,8 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Directory $parent
|
||||
* @param string $path
|
||||
*
|
||||
* @return ContentAbstract
|
||||
*/
|
||||
public static function getOrCreatePage(Directory $parent, $path)
|
||||
@ -184,7 +186,7 @@ class Builder
|
||||
$path .= '.md';
|
||||
}
|
||||
|
||||
$raw = !in_array($extension, $parent->getConfig()['valid_content_extensions']);
|
||||
$raw = !in_array($extension, $parent->getConfig()->getValidContentExtensions());
|
||||
|
||||
$title = $uri = $path;
|
||||
if (!$raw) {
|
||||
@ -212,11 +214,10 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the tree recursively
|
||||
*
|
||||
* @param Directory $current
|
||||
* Sort the tree recursively.
|
||||
*/
|
||||
public static function sortTree(Directory $current) {
|
||||
public static function sortTree(Directory $current)
|
||||
{
|
||||
$current->sort();
|
||||
foreach ($current->getEntries() as $entry) {
|
||||
if ($entry instanceof Directory) {
|
||||
@ -226,10 +227,10 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next and previous for all pages
|
||||
* Calculate next and previous for all pages.
|
||||
*
|
||||
* @param Directory $current
|
||||
* @param null|Content $prev
|
||||
*
|
||||
* @return null|Content
|
||||
*/
|
||||
public static function finalizeTree(Directory $current, $prev = null)
|
||||
@ -249,5 +250,4 @@ class Builder
|
||||
|
||||
return $prev;
|
||||
}
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user