Enhance project handling for websites in portfolio
Sync TODOs with Issues / sync_todos (push) Successful in 6s

- Added methods in Projects class to determine if a project is a website, retrieve its URL, platform, and screenshot.
- Updated single-project template to display website-specific information and actions.
- Modified project card component to show website details and adjust action buttons accordingly.
- Improved CSS for project cards and buttons to align with new website features.
This commit is contained in:
Keith Solomon
2026-08-22 15:14:28 -05:00
parent d0dd9fa98a
commit 0613e33411
7 changed files with 382 additions and 264 deletions
+53
View File
@@ -139,4 +139,57 @@ class Projects {
}
return number_format( $value );
}
/**
* Whether the project is configured as a website rather than a git repo.
*
* @param int $post_id Project post ID.
* @return bool
*/
public static function is_website( int $post_id ): bool {
if ( ! self::is_plugin_active() ) {
return false;
}
return (bool) projects_portfolio_is_website( $post_id );
}
/**
* Public URL for the project's website (or empty string).
*
* @param int $post_id Project post ID.
* @return string
*/
public static function get_site_url( int $post_id ): string {
if ( ! self::is_plugin_active() ) {
return '';
}
return (string) projects_portfolio_get_site_url( $post_id );
}
/**
* Platform label for the project's website (or empty string).
*
* @param int $post_id Project post ID.
* @return string
*/
public static function get_site_platform( int $post_id ): string {
if ( ! self::is_plugin_active() ) {
return '';
}
return (string) projects_portfolio_get_site_platform( $post_id );
}
/**
* Screenshot attachment URL for the project's website (or empty string).
*
* @param int $post_id Project post ID.
* @param string $size Registered image size.
* @return string
*/
public static function get_site_screenshot_url( int $post_id, string $size = 'large' ): string {
if ( ! self::is_plugin_active() ) {
return '';
}
return (string) projects_portfolio_get_site_screenshot_url( $post_id, $size );
}
}
+35 -4
View File
@@ -17,7 +17,11 @@ get_header();
while ( have_posts() ) :
the_post();
$project_id = (int) get_the_ID();
$provider = Projects::get_provider_label( $project_id );
$is_website = Projects::is_website( $project_id );
$site_url = Projects::get_site_url( $project_id );
$site_platform = Projects::get_site_platform( $project_id );
$site_shot_url = Projects::get_site_screenshot_url( $project_id, 'large' );
$provider = $is_website ? __( 'Website', 'ks-portfolio' ) : Projects::get_provider_label( $project_id );
$version = Projects::get_latest_version( $project_id );
$release = Projects::get_release_url( $project_id );
$repo = Projects::get_repo_browse_url( $project_id );
@@ -39,7 +43,7 @@ while ( have_posts() ) :
</p>
<h1 class="single-project__title">
<?php echo esc_html( get_the_title( $project_id ) ); ?>
<?php if ( 'Unknown' !== $version ) : ?>
<?php if ( ! $is_website && 'Unknown' !== $version ) : ?>
<span class="single-project__version">v<?php echo esc_html( $version ); ?></span>
<?php endif; ?>
</h1>
@@ -48,6 +52,13 @@ while ( have_posts() ) :
<?php endif; ?>
<div class="single-project__actions">
<?php if ( $is_website ) : ?>
<?php if ( $site_url ) : ?>
<a class="button button--primary" href="<?php echo esc_url( $site_url ); ?>" target="_blank" rel="noopener noreferrer">
<?php echo esc_html__( 'Visit Site', 'ks-portfolio' ); ?>
</a>
<?php endif; ?>
<?php else : ?>
<?php if ( $release ) : ?>
<a class="button button--primary" href="<?php echo esc_url( Projects::get_download_url( $project_id ) ); ?>" rel="nofollow">
<?php echo esc_html__( 'Download', 'ks-portfolio' ); ?>
@@ -61,12 +72,19 @@ while ( have_posts() ) :
<?php echo esc_html__( 'View Repo', 'ks-portfolio' ); ?>
</a>
<?php endif; ?>
<?php endif; ?>
</div>
</header>
<div class="single-project__layout">
<div class="single-project__body">
<?php if ( has_post_thumbnail( $project_id ) ) : ?>
<?php if ( $is_website && $site_shot_url ) : ?>
<figure class="single-project__screenshot">
<a href="<?php echo esc_url( $site_url ); ?>" target="_blank" rel="noopener noreferrer">
<img src="<?php echo esc_url( $site_shot_url ); ?>" alt="<?php echo esc_attr( get_the_title( $project_id ) ); ?>" />
</a>
</figure>
<?php elseif ( has_post_thumbnail( $project_id ) ) : ?>
<figure class="single-project__featured">
<?php echo get_the_post_thumbnail( $project_id, 'large' ); ?>
</figure>
@@ -78,7 +96,19 @@ while ( have_posts() ) :
</section>
</div>
<aside class="single-project__sidebar" aria-label="<?php echo esc_attr__( 'Repository details', 'ks-portfolio' ); ?>">
<aside class="single-project__sidebar" aria-label="<?php echo esc_attr__( $is_website ? __( 'Website details', 'ks-portfolio' ) : __( 'Repository details', 'ks-portfolio' ) ); ?>">
<?php if ( $is_website ) : ?>
<?php if ( $site_platform ) : ?>
<section class="single-project__details">
<h3><?php echo esc_html__( 'Website Details', 'ks-portfolio' ); ?></h3>
<?php
set_query_var( 'label', __( 'Platform', 'ks-portfolio' ) );
set_query_var( 'value', $site_platform );
get_template_part( 'views/components/project-meta-row' );
?>
</section>
<?php endif; ?>
<?php else : ?>
<?php if ( $owner ) : ?>
<section class="single-project__maintainer">
<h3><?php echo esc_html__( 'Maintainer', 'ks-portfolio' ); ?></h3>
@@ -155,6 +185,7 @@ while ( have_posts() ) :
endforeach;
?>
</section>
<?php endif; ?>
</aside>
</div>
</div>
+26 -26
View File
@@ -1,6 +1,6 @@
/* Theme color definitions */
@theme {
@theme static {
--color-black: oklch(0% 0 0);
--color-white: oklch(100% 0 0);
@@ -38,32 +38,32 @@
--color-dark: oklch(34.51% 0.0133 248.2);
/* Carbon Blue / dark surface tokens (Portfolio 2026) */
--color-surface: #121318;
--color-surface-dim: #121318;
--color-surface-bright: #38393f;
--color-surface-container-lowest: #0d0e13;
--color-surface-container-low: #1a1b21;
--color-surface-container: #1e1f25;
--color-surface-container-high: #292a2f;
--color-surface-container-highest: #34343a;
--color-on-surface: #e3e1e9;
--color-on-surface-variant: #c5c5d3;
--color-outline: #8f909d;
--color-outline-variant: #444651;
--color-page-base: #100e0b;
--color-backlight: rgba(96, 165, 250, 0.20);
--color-surface: oklch(18.79% 0.0103 276.4);
--color-surface-dim: oklch(18.79% 0.0103 276.4);
--color-surface-bright: oklch(34.59% 0.0105 278.3);
--color-surface-container-lowest: oklch(16.51% 0.0106 276.3);
--color-surface-container-low: oklch(22.37% 0.0117 277.9);
--color-surface-container: oklch(24.08% 0.0115 278);
--color-surface-container-high: oklch(28.6% 0.0092 276.8);
--color-surface-container-highest: oklch(32.74% 0.0105 285.8);
--color-on-surface: oklch(91.36% 0.011 297.6);
--color-on-surface-variant: oklch(82.77% 0.0194 286);
--color-outline: oklch(65.68% 0.0192 282.3);
--color-outline-variant: oklch(39.65% 0.0187 277.4);
--color-page-base: oklch(16.5% 0.007 78.1);
--color-backlight: oklch(71.37% 0.1434 254.6 / 0.2);
--color-primary-fixed: #dce1ff;
--color-primary-fixed-dim: #b6c4ff;
--color-on-primary: #05297a;
--color-on-primary-fixed: #00164e;
--color-on-primary-fixed-variant: #264191;
--color-primary-fixed: oklch(91.52% 0.0412 278.1);
--color-primary-fixed-dim: oklch(83.03% 0.0845 274.1);
--color-on-primary: oklch(32.02% 0.1432 262.8);
--color-on-primary-fixed: oklch(23.06% 0.1072 262.1);
--color-on-primary-fixed-variant: oklch(40.35% 0.1363 266.3);
--color-primary-12: rgba(182, 196, 255, 0.12);
--color-primary-87: #dce1ff;
--color-primary-12: oklch(83.03% 0.0845 274.1 / 0.12);
--color-primary-87: oklch(91.52% 0.0412 278.1);
--color-success: #5ccf91;
--color-warning: #f4e04d;
--color-danger: #cc3b3b;
--color-info: #3d7ab0;
--color-success: oklch(77.17% 0.1386 157.2);
--color-warning: oklch(91.37% 0.1234 97.2);
--color-danger: oklch(54.12% 0.1456 29.8);
--color-info: oklch(45.67% 0.1345 210.3);
}
+9 -4
View File
@@ -39,7 +39,7 @@
* text-75px | 32.00 | 39.46 | 43.25 | 50.30 | 57.36 | 61.77 | 75.00
*/
@theme {
@theme static {
--font-sans: "Raleway", sans-serif;
--font-headings: var(--font-sans);
--line-height: 1.6;
@@ -140,10 +140,15 @@ p {
margin-bottom: 1rem;
}
ul, ol { margin: 0 0 1rem 1.5rem; padding: 0; }
ul { list-style-type: disc; }
ul {
list-style-type: disc;
}
ol { list-style-type: decimal; }
ol {
list-style-type: decimal;
}
li ul, li ol { margin: 0 1rem; }
@@ -169,7 +174,7 @@ pre code {
padding: 0;
}
code { @apply bg-black/30 px-0.25 py-0.5 font-mono text-black text-xs rounded-sm; }
code { @apply bg-white/30 px-0.25 py-0.25 font-mono text-black rounded-sm; }
hr {
background-color: black;
+56 -48
View File
@@ -1,6 +1,6 @@
/* Button styles */
@theme {
@theme inline {
/* Configuration */
/**
@@ -18,14 +18,14 @@
* --button-outline-color (fallback is --button-border-color)
*/
--button-bg: var(--color-primary);
--button-color: var(--color-white);
--button-bg: var(--color-on-primary-fixed-variant);
--button-color: var(--color-primary-fixed-dim);
--button-hover-bg: var(--color-info);
--button-hover-border-color: var(--color-info);
--button-hover-color: var(--color-white);
--button-border-width: 3px;
--button-border-style: solid;
--button-border-color: var(--button-bg);
--button-border-color: var(--color-primary-fixed-dim);
--button-radius: 0.5rem;
}
@@ -50,11 +50,14 @@
&[data-button-variant="outline"] {
background: transparent;
&:hover { background: transparent; }
color: var(--button-border-color);
border-color: var(--button-bg);
--button-color: var(--button-outline-color, var(--button-bg));
--button-hover-border-color: var(--button-hover-bg);
--button-hover-color: var(--button-hover-bg);
&:hover {
background: transparent;
border-color: var(--button-hover-bg);
color: var(--button-hover-color);
}
}
}
@@ -76,20 +79,39 @@
/* Back To Top Button */
#backToTopBtn {
display:none;
position:fixed;
bottom:2rem;
right:2rem;
z-index:1000;
padding:0.75em 1.5em;
font-size:1.1rem;
border-radius:2em;
background:var(--color-primary,#3857BC);
color:#fff;
border:none;
box-shadow:0 2px 8px rgba(0,0,0,0.15);
cursor:pointer;
transition:opacity 0.2s;
background: var(--color-primary,#3857BC);
border: none;
border-radius: 2em;
bottom: 2rem;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
color: #fff;
cursor: pointer;
display: none;
font-size: 1.1rem;
padding: 0.75em 1.5em;
position: fixed;
right: 2rem;
transition: opacity 0.2s;
z-index: 1000;
}
.back-to-top {
background: var(--color-primary, #3857BC);
border: none;
border-radius: 2em;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
color: #fff;
cursor: pointer;
font-size: 1.1rem;
opacity: 0.85;
padding: 0.75em 1.5em;
transition: opacity 0.2s, background 0.2s;
&:hover, &:focus {
background: var(--color-info, #233a7a);
opacity: 1;
outline: 2px solid var(--color-info, #233a7a);
}
}
/**
@@ -157,24 +179,6 @@ x-button:has(.button[data-button-width="full"]) { @apply w-full; }
--button-hover-color: var(--color-dark);
}
.back-to-top {
background: var(--color-primary, #3857BC);
color: #fff;
border: none;
border-radius: 2em;
padding: 0.75em 1.5em;
font-size: 1.1rem;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
cursor: pointer;
transition: opacity 0.2s, background 0.2s;
opacity: 0.85;
}
.back-to-top:hover, .back-to-top:focus {
background: var(--color-info, #233a7a);
opacity: 1;
outline: 2px solid var(--color-info, #233a7a);
}
/* Dark-surface button variants (WCAG-AA against #100e0b) */
.button {
display: inline-flex;
@@ -191,6 +195,7 @@ x-button:has(.button[data-button-width="full"]) { @apply w-full; }
}
.button:active { transform: scale(0.99); }
@media (prefers-reduced-motion: reduce) { .button:active { transform: none; } }
.button:focus-visible { outline: 2px solid var(--color-primary, #b6c4ff); outline-offset: 3px; }
@@ -199,20 +204,22 @@ x-button:has(.button[data-button-width="full"]) { @apply w-full; }
background: var(--color-primary, #b6c4ff);
color: var(--color-on-primary, #05297a);
border-color: var(--color-primary, #b6c4ff);
&:hover { background: var(--color-primary-87, #dce1ff); border-color: var(--color-primary-87, #dce1ff); }
}
.button--primary:hover { background: var(--color-primary-87, #dce1ff); border-color: var(--color-primary-87, #dce1ff); }
.button--outline {
background: transparent;
color: var(--color-on-surface, #e3e1e9);
border-color: var(--color-outline, #8f909d);
color: var(--color-on-surface, #e3e1e9);
&:hover { border-color: var(--color-primary, #b6c4ff); color: var(--color-primary, #b6c4ff); }
}
.button--outline:hover { border-color: var(--color-primary, #b6c4ff); color: var(--color-primary, #b6c4ff); }
.button--secondary {
background: var(--color-surface-container-high, #292a2f);
color: var(--color-on-surface, #e3e1e9);
border-color: var(--color-outline-variant, #444651);
color: var(--color-on-surface, #e3e1e9);
}
/* Outline button over the site-header's bg-secondary surface needs lighter text
@@ -220,10 +227,11 @@ x-button:has(.button[data-button-width="full"]) { @apply w-full; }
* Pure white clears 4.5:1 against #6e757f; --color-on-primary (#05297a) is too
* dark and drops to 2.81:1, so we go to --color-white instead. */
.site-header .button--outline {
color: var(--color-white, #ffffff);
border-color: var(--color-white, #ffffff);
}
.site-header .button--outline:hover {
color: var(--color-primary-87, #dce1ff);
color: var(--color-white, #ffffff);
&:hover {
border-color: var(--color-primary-87, #dce1ff);
color : var(--color-primary-87, #dce1ff);
}
}
+11 -5
View File
@@ -66,6 +66,7 @@
margin: 0;
display: -webkit-box;
-webkit-line-clamp: 4;
line-clamp: 4;
-webkit-box-orient: vertical;
overflow: hidden;
}
@@ -96,23 +97,22 @@
text-decoration: none;
border: 2px solid transparent;
transition: color 200ms ease, background-color 200ms ease, border-color 200ms ease;
&:hover { background: var(--color-primary-87); border-color: var(--color-primary-87); }
}
.project-card__action--primary {
background: var(--color-primary, #b6c4ff);
color: var(--color-on-primary, #05297a);
background: var(--color-primary);
color: #fff;
border-color: var(--color-primary, #b6c4ff);
}
.project-card__action--primary:hover { background: var(--color-primary-87); border-color: var(--color-primary-87); }
.project-card__action--secondary {
color: var(--color-on-surface, #e3e1e9);
border-color: var(--color-outline, #8f909d);
}
.project-card__action--secondary:hover { border-color: var(--color-primary, #b6c4ff); color: var(--color-primary, #b6c4ff); }
.project-card__action:focus-visible {
outline: 2px solid var(--color-primary, #b6c4ff);
outline-offset: 3px;
@@ -327,3 +327,9 @@
}
.home-recent__empty { text-align: center; padding: 4rem 1rem; color: var(--color-on-surface-variant, #c5c5d3); }
/* Website-mode project card + single-project screenshot/platform */
.single-project__screenshot { margin: 0 0 1.5rem; }
.single-project__screenshot img { width: 100%; height: auto; border-radius: 0.75rem; display: block; border: 1px solid var(--color-outline-variant, #444651); }
.project-card__platform { color: var(--color-on-surface-variant, #c5c5d3); font-size: 0.875rem; }
+17 -2
View File
@@ -20,6 +20,9 @@ $type_terms = get_the_terms( $project_id, 'project-type' );
if ( ! empty( $type_terms ) && ! is_wp_error( $type_terms ) ) {
$type_label = strtoupper( $type_terms[0]->name );
}
$is_website = Projects::is_website( $project_id );
$site_url = Projects::get_site_url( $project_id );
$site_platform = Projects::get_site_platform( $project_id );
$release_url = Projects::get_release_url( $project_id );
$repo_url = Projects::get_repo_browse_url( $project_id );
$repo_data = Projects::get_repo_data( $project_id );
@@ -35,7 +38,7 @@ $card_classes = 'project-card group';
<span class="project-card__type"><?php echo esc_html( $type_label ); ?></span>
<?php endif; ?>
<span class="project-card__provider" aria-hidden="true">
<?php echo esc_html( Projects::get_provider_label( $project_id ) ); ?>
<?php echo esc_html( $is_website ? __( 'Website', 'ks-portfolio' ) : Projects::get_provider_label( $project_id ) ); ?>
</span>
</header>
@@ -50,7 +53,7 @@ $card_classes = 'project-card group';
<?php endif; ?>
<footer class="project-card__foot">
<?php if ( $language || $stars > 0 ) : ?>
<?php if ( ! $is_website && ( $language || $stars > 0 ) ) : ?>
<div class="project-card__meta">
<?php if ( $language ) : ?>
<span class="project-card__lang"><?php echo esc_html( $language ); ?></span>
@@ -59,9 +62,20 @@ $card_classes = 'project-card group';
<span class="project-card__stars" aria-label="<?php echo esc_attr( $stars . ' stars' ); ?>">★ <?php echo esc_html( (string) $stars ); ?></span>
<?php endif; ?>
</div>
<?php elseif ( $is_website && $site_platform ) : ?>
<div class="project-card__meta">
<span class="project-card__platform"><?php echo esc_html( $site_platform ); ?></span>
</div>
<?php endif; ?>
<div class="project-card__actions">
<?php if ( $is_website ) : ?>
<?php if ( $site_url ) : ?>
<a class="project-card__action project-card__action--primary" href="<?php echo esc_url( $site_url ); ?>" target="_blank" rel="noopener noreferrer">
<?php echo esc_html__( 'Visit Site', 'ks-portfolio' ); ?>
</a>
<?php endif; ?>
<?php else : ?>
<?php if ( $release_url ) : ?>
<a class="project-card__action project-card__action--primary" href="<?php echo esc_url( Projects::get_download_url( $project_id ) ); ?>" rel="nofollow">
<?php echo esc_html__( 'Download', 'ks-portfolio' ); ?>
@@ -72,6 +86,7 @@ $card_classes = 'project-card group';
<?php echo esc_html__( 'View Repo', 'ks-portfolio' ); ?>
</a>
<?php endif; ?>
<?php endif; ?>
</div>
</footer>
</article>