-
-
Notifications
You must be signed in to change notification settings - Fork 21
Add configuration-based visibility control for sections and elements #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
coderdiaz
merged 3 commits into
coderdiaz:main
from
shrvansudhakara:feature/config-flags
Nov 10, 2025
+194
β55
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Site Configuration - Control visibility of sections | ||
| sections: | ||
| about: true | ||
| workExperience: true | ||
| talks: true | ||
| writing: true | ||
| socialLinks: true | ||
|
|
||
| # Individual elements | ||
| elements: | ||
| avatar: true | ||
| themeSwitch: true | ||
| header: true | ||
| footer: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| --- | ||
| import Container from '@/components/Container.astro'; | ||
| import { getSiteConfig } from '@/lib/config'; | ||
| const config = getSiteConfig(); | ||
| --- | ||
|
|
||
| <Container as='footer' class='pt-24'> | ||
| <p class="text-center text-muted-foreground text-sm"> | ||
| © {new Date().getFullYear()}. Powered by <a href="https://astro.build" target="_blank" rel="noopener noreferrer">Astro</a> and CVfolio. | ||
| </p> | ||
| </Container> | ||
| {config.elements.footer && ( | ||
| <Container as='footer' class='pt-24'> | ||
| <p class="text-center text-muted-foreground text-sm"> | ||
| © {new Date().getFullYear()}. Powered by <a href="https://astro.build" target="_blank" rel="noopener noreferrer">Astro</a> and CVfolio. | ||
| </p> | ||
| </Container> | ||
| )} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,49 @@ | ||
| --- | ||
| import Container from '@/components/Container.astro'; | ||
| import { getSiteConfig } from '@/lib/config'; | ||
|
|
||
| const pathname = Astro.url.pathname; | ||
|
|
||
| const isHomePage = pathname === '/'; | ||
| const isWritingPage = pathname.startsWith('/writing'); | ||
| --- | ||
|
|
||
| <Container | ||
| as="header" | ||
| class="w-full max-w-full flex justify-center items-center" | ||
| > | ||
| <div | ||
| class="w-max fixed top-0 mt-5 bg-muted-foreground/40 backdrop-blur-3xl border border-border rounded-full p-1" | ||
| const config = getSiteConfig(); | ||
| --- | ||
| {config.elements.header && ( | ||
| <Container | ||
| as="header" | ||
| class="w-full max-w-full flex justify-center items-center" | ||
| > | ||
| <nav class="flex items-center"> | ||
| <ul class="flex items-center gap-1"> | ||
| <li> | ||
| <a | ||
| href="/" | ||
| class:list={[ | ||
| 'font-medium transition-colors block px-5 py-2', | ||
| 'hover:text-headings', | ||
| isHomePage && 'text-headings bg-muted-foreground/40 rounded-full', | ||
| ]}>Home</a | ||
| > | ||
| </li> | ||
| <li> | ||
| <a | ||
| href="/writing" | ||
| class:list={[ | ||
| 'font-medium transition-colors block px-5 py-2', | ||
| 'hover:text-headings', | ||
| isWritingPage && | ||
| 'text-headings bg-muted-foreground/40 rounded-full', | ||
| ]}>Writing</a | ||
| > | ||
| </li> | ||
| </ul> | ||
| </nav> | ||
| </div> | ||
| </Container> | ||
| <div | ||
| class="w-max fixed top-0 mt-5 bg-muted-foreground/40 backdrop-blur-3xl border border-border rounded-full p-1" | ||
| > | ||
| <nav class="flex items-center"> | ||
| <ul class="flex items-center gap-1"> | ||
| <li> | ||
| <a | ||
| href="/" | ||
| class:list={[ | ||
| 'font-medium transition-colors block px-5 py-2', | ||
| 'hover:text-headings', | ||
| isHomePage && 'text-headings bg-muted-foreground/40 rounded-full', | ||
| ]}>Home</a | ||
| > | ||
| </li> | ||
| {config.sections.writing && ( | ||
| <li> | ||
| <a | ||
| href="/writing" | ||
| class:list={[ | ||
| 'font-medium transition-colors block px-5 py-2', | ||
| 'hover:text-headings', | ||
| isWritingPage && | ||
| 'text-headings bg-muted-foreground/40 rounded-full', | ||
| ]}>Writing</a | ||
| > | ||
| </li> | ||
| )} | ||
| </ul> | ||
| </nav> | ||
| </div> | ||
| </Container> | ||
| )} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import yaml from 'js-yaml'; | ||
|
|
||
| interface SiteConfig { | ||
| sections: { | ||
| about: boolean; | ||
| workExperience: boolean; | ||
| talks: boolean; | ||
| writing: boolean; | ||
| socialLinks: boolean; | ||
| }; | ||
| elements: { | ||
| avatar: boolean; | ||
| themeSwitch: boolean; | ||
| header: boolean; | ||
| footer: boolean; | ||
| }; | ||
| } | ||
|
|
||
| const defaultConfig: SiteConfig = { | ||
| sections: { | ||
| about: true, | ||
| workExperience: true, | ||
| talks: true, | ||
| writing: true, | ||
| socialLinks: true, | ||
| }, | ||
| elements: { | ||
| avatar: true, | ||
| themeSwitch: true, | ||
| footer: true, | ||
| header: true, | ||
| }, | ||
| }; | ||
|
|
||
| function deepMerge(target: any, source: any): any { | ||
| // Recursively merge source into target | ||
| for (const key of Object.keys(source)) { | ||
| if ( | ||
| source[key] && | ||
| typeof source[key] === 'object' && | ||
| !Array.isArray(source[key]) | ||
| ) { | ||
| if (!target[key] || typeof target[key] !== 'object') { | ||
| target[key] = {}; | ||
| } | ||
| deepMerge(target[key], source[key]); | ||
| } else { | ||
| if (target[key] === undefined) { | ||
| target[key] = source[key]; | ||
| } | ||
| } | ||
| } | ||
| return target; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| export function getSiteConfig(): SiteConfig { | ||
| const configPath = path.join(process.cwd(), 'config.yml'); | ||
| let loadedConfig: any = {}; | ||
| try { | ||
| const fileContents = fs.readFileSync(configPath, 'utf8'); | ||
| loadedConfig = yaml.load(fileContents); | ||
| if (!loadedConfig || typeof loadedConfig !== 'object') { | ||
| console.warn('config.yml is empty or not a valid YAML object, using defaults'); | ||
| return defaultConfig; | ||
| } | ||
| // Merge loaded config with defaults | ||
| const mergedConfig = deepMerge(loadedConfig, defaultConfig); | ||
| if (!isValidConfig(mergedConfig)) { | ||
| console.warn('config.yml is malformed or missing required fields, using defaults'); | ||
| return defaultConfig; | ||
| } | ||
| return mergedConfig as SiteConfig; | ||
| } catch (error: any) { | ||
| if (error.code === 'ENOENT') { | ||
| console.warn('config.yml not found, using defaults'); | ||
| } else if (error.name === 'YAMLException' || error instanceof yaml.YAMLException) { | ||
| console.warn('config.yml is malformed YAML, using defaults'); | ||
| } else { | ||
| console.warn(`Error loading config.yml: ${error.message}, using defaults`); | ||
| } | ||
| return defaultConfig; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.