public function createTableOfContent()
    {
        $basepath   = $this->config['basepath'];
        $pattern    = $this->config['pattern'];
        $route      = $this->di->request->getRoute();

        // if dir, add index if file exists.
        // partly for adding doc/index to work
        // partly to make doc/ generate proper toc.
        $baseroute  = dirname($route);
        $path       = $basepath . '/' . $baseroute . '/' . $pattern;

        $toc = [];
        foreach (glob($path) as $file) {
            $parts    = pathinfo($file);
            $filename = $parts['filename'];

            $title = $this->getTitleFromFirstLine($file);
            $file2route = substr($filename, strpos($filename, '_') + 1);

            $url = $baseroute . '/' . $file2route;
            /*
            if ($file2route == 'index' ) {
                $url = $baseroute;
            }*/

            // Create level depending on the file id
            $id = substr($filename, 0, strpos($filename, '_'));
            $level = 2;
            if ($id % 100 === 0) {
                $level = 0;
            } elseif ($id % 10 === 0) {
                $level = 1;
            }

            $toc[$url] = [
                'title'     => $title,
                'filename'  => $parts['basename'],
                'level'     => $level,
            ];
        }

        return $toc;
    }
public function createTableOfContent()
    {
        $basepath   = $this->config['basepath'];
        $pattern    = $this->config['pattern'];
        $route      = $this->di->request->getRoute();

        // if dir, add index if file exists.
        // partly for adding doc/index to work
        // partly to make doc/ generate proper toc.
        $baseroute  = dirname($route);
        $path       = $basepath . '/' . $baseroute . '/' . $pattern;

        $toc = [];
        foreach (glob($path) as $file) {
            $parts    = pathinfo($file);
            $filename = $parts['filename'];

            $title = $this->getTitleFromFirstLine($file);
            $file2route = substr($filename, strpos($filename, '_') + 1);

            $url = $baseroute . '/' . $file2route;
            /*
            if ($file2route == 'index' ) {
                $url = $baseroute;
            }*/

            // Create level depending on the file id
            $id = substr($filename, 0, strpos($filename, '_'));
            $level = 2;
            if ($id % 100 === 0) {
                $level = 0;
            } elseif ($id % 10 === 0) {
                $level = 1;
            }

            $toc[$url] = [
                'title'     => $title,
                'filename'  => $parts['basename'],
                'level'     => $level,
            ];
        }

        return $toc;
    }
public function createTableOfContent ( ) { $ basepath = $ this -> config [ 'basepath' ] ; $ pattern = $ this -> config [ 'pattern' ] ; $ route = $ this -> di -> request -> getRoute ( ) ; // if dir, add index if file exists. // partly for adding doc/index to work // partly to make doc/ generate proper toc. $ baseroute = dirname ( $ route ) ; $ path = $ basepath . '/' . $ baseroute . '/' . $ pattern ; $ toc = [ ] ; foreach ( glob ( $ path ) as $ file ) { $ parts = pathinfo ( $ file ) ; $ filename = $ parts [ 'filename' ] ; $ title = $ this -> getTitleFromFirstLine ( $ file ) ; $ file2route = substr ( $ filename , strpos ( $ filename , '_' ) + 1 ) ; $ url = $ baseroute . '/' . $ file2route ; /*
            if ($file2route == 'index' ) {
                $url = $baseroute;
            }*/ // Create level depending on the file id $ id = substr ( $ filename , 0 , strpos ( $ filename , '_' ) ) ; $ level = 2 ; if ( $ id % 100 === 0 ) { $ level = 0 ; } elseif ( $ id % 10 === 0 ) { $ level = 1 ; } $ toc [ $ url ] = [ 'title' => $ title , 'filename' => $ parts [ 'basename' ] , 'level' => $ level , ] ; } return $ toc ; }
Generate ToC from directory structure, containing url, title and filename
of each page.

@return array as table of content.
Generate ToC from directory structure containing url title and filename of each page .