Skip to content

Commit

Permalink
Updates for 0.2-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
eugabrielsilva committed May 12, 2022
1 parent 0436f09 commit 2e46a84
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 76 deletions.
19 changes: 15 additions & 4 deletions assets/css/butterdocs.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ section.content {
padding: 50px 80px;
overflow-y: auto;
flex: 0 1 100%;
transition: 0.3s all;
}

section.content:hover::-webkit-scrollbar-thumb {
Expand Down Expand Up @@ -245,7 +246,7 @@ section.not-found {

section.not-found h1 {
color: var(--primary-color);
font-size: 5em;
font-size: 10em;
font-weight: 300;
}

Expand All @@ -269,7 +270,7 @@ section.not-found a i {
margin-right: 7px;
}

@media (max-width: 767px) {
@media (max-width: 991px) {
body {
font-size: 14px;
}
Expand All @@ -279,13 +280,18 @@ section.not-found a i {
}

section.menu {
margin-left: -250px;
position: fixed;
z-index: 1;
left: -100%;
top: 0;
width: 100%;
height: 100%;
padding: 10px 20px;
padding-top: 67px;
}

section.menu.show {
margin-left: 0;
left: 0;
}

section.menu .logo {
Expand All @@ -299,12 +305,17 @@ section.not-found a i {

section.header {
display: block;
z-index: 2;
}

section.not-found {
font-size: 13px;
}

section.not-found h1 {
font-size: 7em;
}

section.not-found a {
font-size: 13px;
margin-top: 10px;
Expand Down
37 changes: 37 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
------------------------
Documentation settings
------------------------
*/

return [

// Application title
'application' => 'ButterDocs',

// Generate menu automatically if not provided
'generate_menu' => true,

// Theme to use (must be a valid theme from "assets/css/themes" folder)
'theme' => 'light',

// Show "Edit this page on GitHub" button
'git_edit' => true,

// GitHub edit URL (including branch)
'git_url' => 'https://github.com/eugabrielsilva/butterdocs/edit/master',

// Enable support to Markdown Extra
'md_extra' => true,

// Enable single line breaks
'md_breaks' => true,

// Enable automatic URL links
'md_urls' => true

];

?>
14 changes: 7 additions & 7 deletions docs/v0.1-alpha/_menu.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
### Getting started
- [Requirements](%%version%%/getting-started/requirements)
- [Installation](%%version%%/getting-started/installation)
- [Configuration](%%version%%/getting-started/configuration)
- [Butter basics](%%version%%/getting-started/butter-basics)
- [Dynamic tags](%%version%%/getting-started/dynamic-tags)
- [Requirements](getting-started/requirements)
- [Installation](getting-started/installation)
- [Configuration](getting-started/configuration)
- [Butter basics](getting-started/butter-basics)
- [Dynamic tags](getting-started/dynamic-tags)

### Customization
- [Themes](%%version%%/customization/themes)
- [Assets](%%version%%/customization/assets)
- [Themes](customization/themes)
- [Assets](customization/assets)
2 changes: 1 addition & 1 deletion docs/v0.1-alpha/customization/assets.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Assets
Your documentation assets (as the logo and favicon) are stored into `assets/images` folder.

Feel free to replace this files with your application art. You can also use this folder to store other images used in your docs, just remember to point the asset URL relatively to ButterDocs root folder. Example: `assets/images/myfilename.png`.
Feel free to replace this files with your application art. You can also use this folder to store other images used in your docs, just remember to point the asset URL relatively to ButterDocs root directory, with one upper level. Example: `../assets/images/myfilename.png`.
1 change: 1 addition & 0 deletions docs/v0.1-alpha/getting-started/butter-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ We recommend using only letters and dashes on the filenames.
There are two files inside each version folder that will be treated differently:

- The `home.md` file will be the entry point of your documentation. This page will be displayed as the index/welcome page of the current version.
**This page must exist in each version folder.**
- The `_menu.md` file will hold the sidenav menu content. This is were you can list your documentation topics. If you do not provide a menu file and the `generate_menu` setting is enabled in the configuration, ButterDocs will generate a menu for the current version using the top-level folders as section headings.

### Example of folder structure
Expand Down
4 changes: 2 additions & 2 deletions docs/v0.1-alpha/getting-started/configuration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Configuration
Your documentation configuration can be found at `index.php` file.
Your documentation configuration can be found at the root `config.php` file.

The options within this file are:

Expand All @@ -10,7 +10,7 @@ Your application title, basically the name that will be displayed in the documen
Enables the automatic sidenav menu generation, if the custom menu file for the current version is not provided.

`theme`
The theme used in your documentation. See [Themes](%%version%%/customization/themes).
The theme used in your documentation. See [Themes](customization/themes).

`git_edit`
Enables the "Edit this page on GitHub" button.
Expand Down
4 changes: 2 additions & 2 deletions docs/v0.1-alpha/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
That's all! Simple, isn't it?

### Setup your docs
You'll probably want to [configure](%%version%%/getting-started/configuration) your docs before getting started.
You'll probably want to [configure](getting-started/configuration) your docs before getting started.

If you want to skip this step and jump straight into writing your docs, [be happy](%%version%%/getting-started/butter-basics).
If you want to skip this step and jump straight into writing your docs, [be happy](getting-started/butter-basics).
42 changes: 6 additions & 36 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
<?php

/*
------------------------
Documentation settings
------------------------
--------------------------
Application bootstrapper
Do not edit this file!
--------------------------
*/

define('APP_CONFIG', [

// Application title
'application' => 'ButterDocs',

// Generate menu automatically if not provided
'generate_menu' => true,

// Theme to use (must be a valid theme from "assets/css/themes" folder)
'theme' => 'light',

// Show "Edit this page on GitHub" button
'git_edit' => true,

// GitHub edit URL (including branch)
'git_url' => 'https://github.com/eugabrielsilva/butterdocs/edit/master',

// Enable support to Markdown Extra
'md_extra' => true,

// Enable single line breaks
'md_breaks' => true,

// Enable automatic URL links
'md_urls' => true

]);

/*
-----------------------------
Do not edit below this line!
-----------------------------
*/
// Load the settings
define('APP_CONFIG', require_once('config.php'));

// Load the bootstrapper
require_once('src/bootstrapper.php');
Expand Down
40 changes: 26 additions & 14 deletions src/core/ButterDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ public function unleash(){
}

// Creates the parser
if(APP_CONFIG['md_extra']){
if(APP_CONFIG['md_extra'] ?? true){
$parser = new ParsedownExtra();
}else{
$parser = new Parsedown();
}

// Sets the parser options
$parser->setBreaksEnabled(APP_CONFIG['md_breaks']);
$parser->setUrlsLinked(APP_CONFIG['md_urls']);
$parser->setBreaksEnabled(APP_CONFIG['md_breaks'] ?? true);
$parser->setUrlsLinked(APP_CONFIG['md_urls'] ?? true);

// Validate docs content
if(!file_exists($file)){
http_response_code(404);
return $this->view('404.phtml', [
'title' => 'Page not found | ' . APP_CONFIG['application'],
'theme' => APP_CONFIG['theme'],
'title' => 'Page not found | ' . (APP_CONFIG['application'] ?? 'ButterDocs'),
'theme' => APP_CONFIG['theme'] ?? 'light',
'base_url' => $this->baseUrl
]);
}
Expand All @@ -108,7 +108,7 @@ public function unleash(){

// Validates menu content
$menu_file = 'docs/' . $this->version . '/_menu.md';
if(file_exists($menu_file)){
if(is_file($menu_file)){
$menu = file_get_contents($menu_file);
}else{
$menu = $this->generateMenu();
Expand All @@ -123,12 +123,12 @@ public function unleash(){

// Includes the main view
return $this->view('main.phtml', [
'title' => $title . ' | ' . APP_CONFIG['application'],
'title' => $title . ' | ' . (APP_CONFIG['application'] ?? 'ButterDocs'),
'menu' => $menu,
'content' => $content,
'theme' => APP_CONFIG['theme'],
'application' => APP_CONFIG['application'],
'git' => APP_CONFIG['git_edit'] ? (trim(APP_CONFIG['git_url'], '/') . '/' . $file) : '',
'theme' => APP_CONFIG['theme'] ?? 'light',
'application' => APP_CONFIG['application'] ?? 'ButterDocs',
'git' => (APP_CONFIG['git_edit'] ?? true) ? (trim(APP_CONFIG['git_url'] ?? '', '/') . '/' . $file) : '',
'base_url' => $this->baseUrl,
'version' => $this->version,
'version_list' => array_reverse($this->versionList),
Expand All @@ -142,14 +142,26 @@ public function unleash(){
*/
private function generateMenu(){
// Checks if the generate menu setting is enabled
if(!APP_CONFIG['generate_menu']) return '';
if(!(APP_CONFIG['generate_menu'] ?? true)) return '';

// Stores the markdown result
$result = '';

// Loops through standalone files
foreach(glob('docs/' . $this->version . '/*.md') as $file){

// Adds the file
$name = pathinfo($file, PATHINFO_FILENAME);
if($name == 'home') continue;
$name = str_replace('-', ' ', ucfirst($name));
$link = str_replace('.md', '', explode('/', $file, 3)[2]);
$result .= '- [' . $name . '](' . $link. ")\n";

}

// Loops through the version folders
foreach(glob('docs/' . $this->version . '/*', GLOB_ONLYDIR) as $dir){

// Gets the folder files
$files = glob($dir . '/*.md');
if(empty($files)) continue;
Expand All @@ -160,10 +172,10 @@ private function generateMenu(){

// Loops through the folder files
foreach($files as $file){

// Adds the file
$name = str_replace('-', ' ', ucfirst(pathinfo($file, PATHINFO_FILENAME)));
$link = str_replace('.md', '', explode('/', $file, 2)[1]);
$link = str_replace('.md', '', explode('/', $file, 3)[2]);
$result .= '- [' . $name . '](' . $link. ")\n";
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/view/main.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

<head>
<title><?= $title; ?></title>
<base href="<?= $base_url; ?>">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
<link rel="shortcut icon" href="assets/images/favicon.png">
<base href="<?= $base_url . $version . '/'; ?>">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="shortcut icon" href="../assets/images/favicon.png">

<!-- CSS plugins -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.1.0/styles/default.min.css">

<!-- ButterDocs CSS -->
<link rel="stylesheet" href="assets/css/themes/<?= $theme; ?>.css">
<link rel="stylesheet" href="assets/css/butterdocs.css">
<link rel="stylesheet" href="../assets/css/themes/<?= $theme; ?>.css">
<link rel="stylesheet" href="../assets/css/butterdocs.css">
</head>

<body>
<section class="layout">
<!-- Mobile header -->
<section class="header">
<a class="menu-button" onclick="toggleSidenav();"><i class="fas fa-bars"></i></a>
<a href="<?= $version; ?>">
<a href="../<?= $version; ?>">
<?= $application; ?>
</a>
<?php if (!empty($git)) : ?>
Expand All @@ -44,8 +44,8 @@

<!-- Sidenav menu -->
<section class="menu">
<a href="<?= $version; ?>">
<img src="assets/images/logo.png" class="logo">
<a href="../<?= $version; ?>">
<img src="../assets/images/logo.png" class="logo">
</a>
<div class="dropdown">
<a class="dropdown-toggle" data-bs-toggle="dropdown">
Expand All @@ -57,7 +57,7 @@
<ul class="dropdown-menu">
<?php foreach ($version_list as $v) : ?>
<li>
<a href="<?= $v; ?>" class="dropdown-item" href="#">
<a href="../<?= $v; ?>" class="dropdown-item" href="#">
<?= $v; ?>
<?php if ($v == $last_version) : ?>
<span>(latest)</span>
Expand Down Expand Up @@ -87,7 +87,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.1.0/highlight.min.js"></script>

<!-- ButterDocs JS -->
<script src="assets/js/butterdocs.js"></script>
<script src="../assets/js/butterdocs.js"></script>
</body>

</html>

0 comments on commit 2e46a84

Please sign in to comment.