Skip to content

Commit

Permalink
Automatic menu generation and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eugabrielsilva committed Oct 2, 2021
1 parent e5845dd commit 0436f09
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<a href="https://glowie.tk" target="_blank"><img src="https://i.imgur.com/3SrqkTl.png" alt="Glowie" width="200"/></a>
<a href="https://github.com/eugabrielsilva/butterdocs" target="_blank"><img src="https://i.imgur.com/3SrqkTl.png" alt="ButterDocs" width="200"/></a>
</p>

<p align="center">
Expand All @@ -11,11 +11,13 @@
ButterDocs is a lightweight documentation website generator written in PHP. Simply create your Markdown files and ButterDocs will do the rest for you, creating a beautiful and responsive website with your docs.

## Features
- Fast and lightweight
- No static HTML files
- Support for multiple documentation versions
- Syntax highlighting support
- Theme customization
- Automatic routing
- Automatic menu generation
- Responsive layout
- Supports flavored Markdown and Markdown Extra
- Supports direct editing on GitHub
Expand Down
1 change: 1 addition & 0 deletions assets/css/butterdocs.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ section.edit i {

section.menu {
flex: 0 0 250px;
background-color: var(--menu-bg-color);
border-right: 1px solid var(--menu-border-color);
overflow-y: auto;
padding: 30px 20px;
Expand Down
3 changes: 2 additions & 1 deletion assets/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
/* Theme colors */
:root {
--bg-color: #212121;
--menu-bg-color: #272727;
--text-color: #ffffff;
--primary-color: #bdbdbd;
--secondary-color: #757575;
--code-block-color: #f8f8f8;
--code-block-color: #23241f;
--menu-border-color: #424242;
--header-bg-color: #424242;
--header-text-color: #ffffff;
Expand Down
1 change: 1 addition & 0 deletions assets/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/* Theme colors */
:root {
--bg-color: #ffffff;
--menu-bg-color: #fafafa;
--text-color: #212121;
--primary-color: #26a69a;
--secondary-color: #80cbc4;
Expand Down
3 changes: 2 additions & 1 deletion docs/v0.1-alpha/_menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
- [Dynamic tags](%%version%%/getting-started/dynamic-tags)

### Customization
- [Themes](%%version%%/customization/themes)
- [Themes](%%version%%/customization/themes)
- [Assets](%%version%%/customization/assets)
4 changes: 4 additions & 0 deletions docs/v0.1-alpha/customization/assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +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`.
2 changes: 1 addition & 1 deletion docs/v0.1-alpha/getting-started/butter-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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.
- The `_menu.md` file will hold the sidenav menu content. This is were you can list your documentation topics.
- 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
```plaintext
Expand Down
3 changes: 3 additions & 0 deletions docs/v0.1-alpha/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The options within this file are:
`application`
Your application title, basically the name that will be displayed in the documentation titles.

`generate_menu`
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).

Expand Down
3 changes: 3 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// 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',

Expand Down
38 changes: 37 additions & 1 deletion src/core/ButterDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function unleash(){
if(file_exists($menu_file)){
$menu = file_get_contents($menu_file);
}else{
$menu = '';
$menu = $this->generateMenu();
}

// Gets menu content
Expand All @@ -136,6 +136,42 @@ public function unleash(){
]);
}

/**
* Generates the sidenav menu automatically.
* @return string Returns the menu markdown.
*/
private function generateMenu(){
// Checks if the generate menu setting is enabled
if(!APP_CONFIG['generate_menu']) return '';

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

// 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;

// Creates the heading
$name = str_replace('-', ' ', ucfirst(pathinfo($dir, PATHINFO_BASENAME)));
$result .= "\n" . '### ' . $name . "\n";

// 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]);
$result .= '- [' . $name . '](' . $link. ")\n";
}
}

// Returns the result
return $result;
}

/**
* Renders a view file.
* @param string $filename View filename.
Expand Down

0 comments on commit 0436f09

Please sign in to comment.