public function summary($size = null, $textOnly = false)
    {
        $config = (array)Grav::instance()['config']->get('site.summary');
        if (isset($this->header->summary)) {
            $config = array_merge($config, $this->header->summary);
        }

        // Return summary based on settings in site config file
        if (!$config['enabled']) {
            return $this->content();
        }

        // Set up variables to process summary from page or from custom summary
        if ($this->summary === null) {
            $content = $textOnly ? strip_tags($this->content()) : $this->content();
            $summary_size = $this->summary_size;
        } else {
            $content = strip_tags($this->summary);
            // Use mb_strwidth to deal with the 2 character widths characters
            $summary_size = mb_strwidth($content, 'utf-8');
        }

        // Return calculated summary based on summary divider's position
        $format = $config['format'];
        // Return entire page content on wrong/ unknown format
        if (!in_array($format, ['short', 'long'])) {
            return $content;
        }
        if (($format === 'short') && isset($summary_size)) {
            // Use mb_strimwidth to slice the string
            if (mb_strwidth($content, 'utf8') > $summary_size) {
                return mb_substr($content, 0, $summary_size);
            }

            return $content;
        }

        // Get summary size from site config's file
        if ($size === null) {
            $size = $config['size'];
        }

        // If the size is zero, return the entire page content
        if ($size === 0) {
            return $content;
            // Return calculated summary based on defaults
        }
        if (!is_numeric($size) || ($size < 0)) {
            $size = 300;
        }

        // Only return string but not html, wrap whatever html tag you want when using
        if ($textOnly) {
            if (mb_strwidth($content, 'utf-8') <= $size) {
                return $content;
            }

            return mb_strimwidth($content, 0, $size, '...', 'utf-8');
        }

        $summary = Utils::truncateHtml($content, $size);

        return html_entity_decode($summary);
    }