Skip to content

Conversation

@shrvansudhakara
Copy link
Contributor

🗒️ Description

This PR adds support for controlling the visibility of sections and UI elements through a centralized configuration file. Users can now easily show/hide different parts of their portfolio without modifying code.

Fixes #15

📝 Changes

New Files

  • config.yml - Central configuration file for visibility flags
  • src/lib/config.ts - Configuration utility with TypeScript types and YAML parser

Modified Files

  • src/pages/index.astro - Added config checks for sections (Work Experience, Talks, Contact, Avatar)
  • src/components/partials/Header.astro - Added config check for Writing navigation link
  • src/components/partials/Footer.astro - Added config check for footer visibility
  • src/layouts/BaseLayout.astro - Added config check for theme switcher
  • package.json - Added js-yaml dependency for YAML parsing
  • bun.lockb - Updated lock file

🚀 Features

  • Configuration file: Simple config.yml for toggling visibility
  • Section controls: Show/hide Work Experience, Talks, Writing, Social Links sections
  • Element controls: Show/hide Avatar, Theme Switcher, Footer, Header elements
  • No code changes needed: Users can customize their site by editing YAML
  • Type-safe: Full TypeScript support with defined interfaces
  • Defaults provided: Falls back to sensible defaults if config file is missing
  • Hot reload in dev mode: Config changes reflect on browser refresh upon saving, no server restart needed.

🔧 Implementation Details

Configuration structure:

sections:
  workExperience: true
  talks: true
  writing: true
  socialLinks: true

elements:
  avatar: true
  themeSwitch: true
  footer: true
  header: true

Usage pattern:

{config.sections.workExperience && (
  <Container as="section">
    <!-- Work Experience content -->
  </Container>
)}

✅ Testing

  • All sections visible when flags set to true
  • Work Experience section hidden when workExperience: false
  • Talks section hidden when talks: false
  • Writing navigation link hidden when writing: false
  • Social Links section hidden when socialLinks: false
  • Avatar hidden when avatar: false
  • Theme switcher hidden when themeSwitch: false
  • Footer hidden when footer: false
  • Header hidden when header: false
  • Default configuration loads when config.yml is missing
  • Config changes auto refreshes upon saving, no server restart required
  • No TypeScript errors
  • Build succeeds without errors

📖 Usage

To hide any section or element, simply edit config.yml:

sections:
  workExperience: false  # Hides work experience section
  writing: false         # Hides writing section and nav link

elements:
  footer: false          # Hides footer

🔗 Related


Notes:

  • ✅ Auto refresh upon change in yml file works in dev mode
  • ⚠️ Auto refresh upon change in yml file still needs rebuild for production

- Add config.yml for toggling visibility of sections and UI elements
- Implement config utility for dynamic visibility handling
- Add visibility controls for work experience, talks, writing, and social links
- Add visibility controls for avatar, theme switch, footer, and header
- Wrap components with config checks throughout the app
- Install js-yaml for YAML parsing
- Supports live updates without server restart (auto-refresh on save)

Resolves coderdiaz#15
@shrvansudhakara
Copy link
Contributor Author

@coderdiaz Pls review the PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a configuration system that allows users to control the visibility of sections and UI elements on the site through a YAML config file. The implementation adds a new getSiteConfig() function that reads from config.yml and falls back to defaults if the file is not found.

Key changes:

  • Added YAML-based configuration system to toggle visibility of sections (about, work experience, talks, writing, social links) and UI elements (avatar, theme switch, header, footer)
  • Wrapped all configurable sections and elements in conditional rendering blocks based on config values
  • Added js-yaml dependency and its TypeScript types for YAML parsing

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/lib/config.ts New module that exports getSiteConfig() function with YAML parsing and default fallback
src/pages/index.astro Wraps sections (about, social links, work experience, talks) and avatar in conditional rendering
src/layouts/BaseLayout.astro Conditionally renders theme switch based on config
src/components/partials/Header.astro Wraps header and "Writing" nav item in conditional rendering
src/components/partials/Footer.astro Conditionally renders footer based on config
package.json Adds js-yaml and @types/js-yaml dependencies
config.yml New configuration file with all sections and elements enabled by default

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@shrvansudhakara
Copy link
Contributor Author

shrvansudhakara commented Nov 3, 2025

@coderdiaz resolved copilot reviews

Copy link
Owner

@coderdiaz coderdiaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shrvansudhakara Could you explain me about the issue in build production about the config file?

Comment on lines +58 to +94
function isValidConfig(config: any): boolean {
if (
!config ||
typeof config !== 'object' ||
!config.sections ||
typeof config.sections !== 'object' ||
!config.elements ||
typeof config.elements !== 'object'
) {
return false;
}
// Optionally, check for required keys
const sectionKeys = [
'about',
'workExperience',
'talks',
'writing',
'socialLinks',
];
const elementKeys = [
'avatar',
'themeSwitch',
'header',
'footer',
];
for (const key of sectionKeys) {
if (typeof config.sections[key] !== 'boolean') {
return false;
}
}
for (const key of elementKeys) {
if (typeof config.elements[key] !== 'boolean') {
return false;
}
}
return true;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shrvansudhakara What do you think about for use Zed or Yup for schema validation instead of this approach proposed by Copilot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderdiaz, There is no production issue, the config works correctly:

  • Dev mode: Reads config.yml on each request, changes reflect immediately
  • Build: Reads config once per component, generates static HTML
  • Production: Static files only, no config reading at runtime

Copilot flagged it as a "performance concern," but it's a non-issue:

  • File reads are ~1-2ms (negligible in builds)
  • Caching would break dev hot-reload
  • Each build is a fresh process anyway

The implementation is correct as-is for Astro SSG. Just addressing the Copilot reviews for completeness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderdiaz, Using Zod/Yup would be much cleaner and more maintainable, however it would be an add-on on dependency list. I'd prefer Zod, as I worked with it previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for hiding sections and elements from the template with flags

2 participants