/*
Theme Name: Luce
Theme URI: https://wordpress.com/themes/luce/
Description: Simple resume and blog theme with bright personality.
Version: 1.0.2
Author: Automattic
Author URI: https://automattic.com/
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: luce
*/

/*
 * Control the hover stylings of outline block style.
 * Unnecessary once block styles are configurable via theme.json
 * https://github.com/WordPress/gutenberg/issues/42794
 */
.wp-block-button.is-style-outline>.wp-block-button__link:not(.has-background):hover {
	background-color: var(--wp--preset--color--secondary);
	color: var(--wp--preset--color--base);
	border-color: var(--wp--preset--color--secondary);
}

/*
 * Link styles
 * https://github.com/WordPress/gutenberg/issues/42319
 */
a {
	text-decoration-thickness: .0625em !important;
	text-underline-offset: .15em;
}

// Shortcode: [recent_posts]
function custom_recent_posts_shortcode($atts) {
    ob_start();

    // Default attributes
    $atts = shortcode_atts(
        array(
            'posts' => 5, // number of posts
            'category' => '', // slug of category
        ),
        $atts,
        'recent_posts'
    );

    // Query
    $query = new WP_Query(array(
        'posts_per_page' => $atts['posts'],
        'category_name'  => $atts['category'],
        'post_status'    => 'publish',
    ));

    if ($query->have_posts()) {
        echo '<div class="custom-post-list">';
        while ($query->have_posts()) {
            $query->the_post();
            ?>
            <div class="post-item">
                <a href="<?php the_permalink(); ?>">
                    <?php if (has_post_thumbnail()) {
                        the_post_thumbnail('thumbnail');
                    } ?>
                    <h3><?php the_title(); ?></h3>
                </a>
                <p><?php echo wp_trim_words(get_the_excerpt(), 20, '...'); ?></p>
            </div>
            <?php
        }
        echo '</div>';
    } else {
        echo '<p>No posts found.</p>';
    }

    wp_reset_postdata();
    return ob_get_clean();
}
add_shortcode('recent_posts', 'custom_recent_posts_shortcode');
