Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xy2z committed Jan 9, 2017
2 parents 48a011b + c1ff086 commit 09c3feb
Show file tree
Hide file tree
Showing 19 changed files with 1,011 additions and 171 deletions.
Empty file added .gitignore
Empty file.
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

59 changes: 41 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# xyDocs
# PineDocs

**THIS PROJECT IS STILL UNDER DEVELOPMENT.**

xyDocs is a lightweight tool for viewing files in a browser. Great for documentation, wiki, notes, etc.
PineDocs is a simple, lightweight tool for viewing files in a browser. Great for documentation, wiki, notes, etc.

Renders Markdown, HTML, syntax highlighting code, images, GIFs, audio and videos.


Expand All @@ -13,13 +14,26 @@ Renders Markdown, HTML, syntax highlighting code, images, GIFs, audio and videos
## Setup
### Requirements
- PHP 7.0 or above
- Apache or alike
- YAML extension for PHP (https://pecl.php.net/package/yaml)
- Web server: Nginx/Apache/etc


### Setup guide
1. [Download the latest release](https://github.com/xy2z/xyDocs/releases) or `git clone`.
1. [Download the latest release](https://github.com/xy2z/PineDocs/releases) or `git clone`.
1. Edit the `config.yaml` file
1. Setup web server: Apache/Nginx/etc - or use `php -S localhost:89` for testing.
1. Setup the web server (link to examples) - or use `php -S localhost:89` for testing.


## Features
- Cross-platform (currently tested on Ubuntu and Windows)
- Supports unlimited folders (and files of course)
- Supports Markdown and HTML files
- Supports images and GIFs
- Supports audio and video files
- Support text files (regardless of the extension)
- Syntax highlighting for over 169 languages with over 77 themes
- Multiple responsive themes. You can easily create your own theme in CSS
- A simple YAML config file to change the settings


## Configuration
Expand All @@ -32,42 +46,46 @@ Feel free to edit the `config.yaml` file to fit your needs.
- **`content_dir`** (string) Path to the dir you want to use.

#### Optional settings
- **`logo`** (string) Path to the logo. If nothing is set, the PineDocs logo will be used.

- **`index`** (string) Relative path to the index file. Default is array of `index.md`, `index.html`, `index.txt`, `index`.

- **`theme`** (string) Available themes: `default`, `default-dark`, `wiki`, `wiki-dark`.

- **`logo`** (string) Path to the logo. If nothing is set, the `xyDocs` logo will be used.
- **`highlight_theme`** (string) The theme to use for code. See a list at https://highlightjs.org/static/demo/

- **`code_transparent_bg`** (bool) If `true`, all will use the highlight theme. If `false`, the background will be transparent.

- **`open_dirs`** (int|string) The number of levels of dirs that should be opnened on page load. Use `all` to open all dirs.

- **`render_footer`** (bool) Render the menu footer?

- **`exclude_files`** (array) List of files to exclude. Supports regex if the format is /regex/i.


## Todo v1.0
- Responsive themes: default + wiki
- Themes should only be in 1 file? (so you can't fuck up) ('theme_structure' and 'theme_color'?)
- Theme template (in 'themes' dir)
- Security: Are there other ways to go back in a dir like '../'?
- Custom dir for custom themes? (so it won't be lost when upgrading?)
- Config should be ignored? How to keep it from being overwritten.
- Themes should only be in 1 theme (not array)? (so you can't fuck up) ('theme_structure' and 'theme_color'?)
- Config should be git ignored? (To keep it from being overwritten on upgrade)
- Test:
- Test on ubuntu with content_dir? :) (testpingu01)
- Test on Ubuntu with content_dir
- Test images: jpg, png, gif + more?
- Test videos: ogg, etc.
- Test audio files: avi?
- Test in all browser + mobile browsers.

- Test in all browsers + mobile browsers.
- Exclude files/folders in config (glob).

## Known issues
- Work when browser goes back/forward between pages.
- Can't load files with special chars path (maybe encoding?)
- Rendering (binary) files (images/videos/audio etc) bigger than ~50MB. (Possible solution: if the file is over XXMB then show a download link instead)
- Can't load files with special chars path (encoding)


## Future features
- htaccess
- Apache config example file (for github wiki)
- File icons should match file types.
- Remember scroll position when browsing between files (should also work when using the browsers back/forward)
- Bug: Can't render (binary) files (images/videos/audio etc) bigger than ~50MB. (Possible solution: if the file is over XXMB then show a download link instead)
- Search (filenames, dirs and content) (with keypress 'F' to focus, config for binding key)
- Exclude files/folders in config (glob).
- More themes (sepia)
- Markdown: Generate table of contents (config)
- Show error message if filesize is bigger than PHP memory_limit. (instead of php's fatal error)
Expand All @@ -77,9 +95,14 @@ Feel free to edit the `config.yaml` file to fit your needs.
- Support for more markup languages (https://en.wikipedia.org/wiki/Lightweight_markup_language)
- Config: show_file_extensions,
- Make all content links open in new tab (setting)
- Work on shared network drives (need test)
- File actions (in content_path)
- Fullscreen file-content
- Copy file content to clipboard
- Download file
- Switch between raw/rendered (for html, markdown, etc.) (bind to key 'R'?)
- File details (filesize, created, edited, etc.) (bind to key 'D'?)


## License
GNU GPLv3
27 changes: 15 additions & 12 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# See a detailed list of all settings here:
# https://github.com/xy2z/xyDocs/tree/master##configuration
# https://github.com/xy2z/PineDocs/tree/master#configuration
#

# The title of the
title: xyDocs
title: PineDocs

# The directory that contains all the content
content_dir: D:\Test\Docs\Dokumenter
Expand All @@ -16,24 +16,27 @@ logo: Logo.png
#################
# Optional settings:

index: dude/ay/dude.md

# Theme to use.
theme:
- Wiki
# - Wiki
# - Wiki-Dark
# - Default
# - Default-twilight
- Default
- Default-twilight

# Highlight themes: default, monokai, tomorrow, sunbust. See all on https://highlightjs.org/static/demo/.
highlight_theme: Tomorrow-Night
# Code highlighting themes: default, monokai, tomorrow, sunbust, darcula.
# See all on https://highlightjs.org/static/demo/.
highlight_theme: darcula # Tomorrow-Night

# Use transparent bacground on code?
code_transparent_bg: False

open_dirs: 1 # (int or 'all')

# render_footer: true

# Render the menu footer
render_footer: true

#binds:
# search: f
# switch_raw_rendered: r
exclude_files:
- 'index'
- '/\.yaml/'
16 changes: 8 additions & 8 deletions css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ body {


/*** CONTENT ***/
#content {
#content_wrapper {
float: left;
width: 850px;
height: 100%;
Expand Down Expand Up @@ -123,10 +123,10 @@ body {


/*** Text/Markdown ***/
#content p,
#content ul,
#content ol,
#content code {
#content_wrapper p,
#content_wrapper ul,
#content_wrapper ol,
#content_wrapper code {
line-height: 1.5em;
}

Expand Down Expand Up @@ -172,17 +172,17 @@ video {
width: 100%;
}

#content code {
#content_wrapper code {
display: block;
width: 100%;
white-space: pre-wrap;
padding: 1em;
}

#content code.file {
#content_wrapper code.file {
}

#content code.nobg {
#content_wrapper code.nobg {
background: none;
}

4 changes: 2 additions & 2 deletions default-welcome.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Welcome to xyDocs
# Welcome to PineDocs

https://github.com/xy2z/xyDocs
You haven't set the `content_dir` in the `config.yaml` file.
78 changes: 41 additions & 37 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,76 @@
<?php

// Constants
define('xyDocs_version', '1.0.0-beta.1');

// Autoloader
spl_autoload_register(function ($class_name) {
require_once 'php/' . $class_name . '.php';
});

error_reporting(E_ALL);

require_once 'php/toolbox.php';


// Load config.
$config = (object) yaml_parse_file('config.yaml');
xyDocsFile::$content_dir = xy_format_path($config->content_dir);
PineDocs::load_config();


// Get file from ajax call.
if (isset($_GET['action']) && $_GET['action'] == 'get_file_data' && isset($_GET['relative_path'])) {
header('Content-Type: application/json');
$xyDocsFile = new xyDocsFile(xy_format_path($config->content_dir) . xy_urldecode($_GET['relative_path']));
echo $xyDocsFile->get_json_data();
$PineDocsFile = new PineDocsFile(xy_format_path(PineDocs::$config->content_dir . $_GET['relative_path']));
echo json_encode($PineDocsFile->get_data());
exit;
}


// Get tree
require_once 'php/xyTree.php';
$tree = new xyTree($config->content_dir);
$tree = new xyTree();


// Get index file
if (isset(PineDocs::$config->index)) {
$indexes = [PineDocs::$config->index];
} else {
$indexes = ['index.md', 'index.html', 'index.txt', 'index'];
}

$index_found = false;
foreach ($indexes as $index) {
$path = PineDocs::$config->content_dir . $index;
if (file_exists($path)) {
// $content = nl2br(file_get_contents($index));
// $content_path = $index;
$PineDocsFile = new PineDocsFile($path);
$index_data = $PineDocsFile->get_data();
}
}

// Make sure $theme is array.
$theme = $config->theme ?? array('default');
if (!is_array($theme)) {
$theme = array($theme);
if (!$index_found) {
// No index file added.
// Use the first file found?
$content = 'No index file found. Create a file called index.md in the content_dir.';
$content_path = '';
}


// Prepare template.
$main = new xyTemplate('main');
$main->set_data(array(
'title' => $config->title ?? 'xyDocs 1.0',
'theme' => $theme,
'highlight_theme' => strtolower(str_replace(' ', '_', $config->highlight_theme)) ?? 'default',
'logo' => $config->logo ?? '../Logo.png',
'render_footer' => $config->render_footer ?? true,
'search_value' => '',
'search_placeholder' => 'Search here...',
'xyDocs_version' => xyDocs_version,
'js_vars' => array(
'title' => $config->title ?? 'xyDocs',
'code_transparent_bg' => $config->code_transparent_bg ?? false,
'open_dirs' => $config->open_dirs ?? 0
)
// 'search_value' => '',
// 'search_placeholder' => 'Search here...',
));

if (isset($_GET['file'])) {
$content = nl2br(file_get_contents($tree->all_files[$_GET['file']]->full_path));
$content_path = $tree->all_files[$_GET['file']]->full_path;
$tree->active_hash = $_GET['file'];
} else {
$content = nl2br(file_get_contents('default-welcome.md'));
$content_path = 'default-welcome.md';
}

// Set HTML variables
$main->set_html(array(
'menu' => $tree->render_tree_return(),
'content_path' => $content_path,
'content' => $content
'js_vars' => array(
'title' => PineDocs::$config->title,
'code_transparent_bg' => PineDocs::$config->code_transparent_bg,
'open_dirs' => PineDocs::$config->open_dirs,
'index_data' => $index_data
)
));


// Render main template.
$main->render();
Loading

0 comments on commit 09c3feb

Please sign in to comment.