Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 43 additions & 22 deletions scripts/utils/frontmatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,73 @@ function parseYaml(yamlText) {
let inMultilineString = false;
let multilineValue = '';

// Pre-compile regex patterns for better performance
const indentedPropertyRegex = /^\s+\w+:/;
const objectPropertyRegex = /^(\w+):\s*(.+)$/;

/**
* Initialize array for current key if not already initialized
*/
const ensureArray = () => {
if (currentKey && !currentArray) {
result[currentKey] = [];
currentArray = result[currentKey];
}
};

for (let line of lines) {
line = line.trim();
const originalLine = line;
const trimmedLine = line.trim();

// Skip empty lines and comments
if (!line || line.startsWith('#')) {
if (!trimmedLine || trimmedLine.startsWith('#')) {
continue;
}

// Handle multiline strings (for content after frontmatter)
if (inMultilineString) {
if (line === '---' || line === '...') {
if (trimmedLine === '---' || trimmedLine === '...') {
inMultilineString = false;
if (currentKey) {
result[currentKey] = multilineValue.trim();
}
multilineValue = '';
} else {
multilineValue += line + '\n';
multilineValue += trimmedLine + '\n';
}
continue;
}

// Handle object properties within arrays (indented with spaces, not starting with -)
if (indentedPropertyRegex.test(originalLine) && !trimmedLine.startsWith('-') && currentObject) {
const colonIndex = trimmedLine.indexOf(':');
if (colonIndex > 0) {
const key = trimmedLine.substring(0, colonIndex).trim();
const value = trimmedLine.substring(colonIndex + 1).trim();
currentObject[key] = parseValue(value);
}
continue;
}

// Now work with trimmed line for the rest
line = trimmedLine;

// Handle array items
if (line.startsWith('- ')) {
const value = line.substring(2).trim();

// Initialize array if we have a currentKey but no array yet
ensureArray();

// Check if this is an object in an array (like related links)
if (value.includes(':')) {
const objMatch = value.match(/^(\w+):\s*(.+)$/);
const objMatch = objectPropertyRegex.exec(value);
if (objMatch) {
const [, key, objValue] = objMatch;
if (!currentObject) {
currentObject = {};
if (currentArray) {
currentArray.push(currentObject);
}
// Create a new object for this array item
currentObject = {};
if (currentArray) {
currentArray.push(currentObject);
}
currentObject[key] = parseValue(objValue);
}
Expand All @@ -97,18 +128,8 @@ function parseYaml(yamlText) {
if (currentArray) {
currentArray.push(parseValue(value));
}
}
continue;
}

// Handle object properties within arrays (indented)
if (line.startsWith(' ') && currentObject) {
const objLine = line.substring(2);
const colonIndex = objLine.indexOf(':');
if (colonIndex > 0) {
const key = objLine.substring(0, colonIndex).trim();
const value = objLine.substring(colonIndex + 1).trim();
currentObject[key] = parseValue(value);
// Reset currentObject since this is not an object array item
currentObject = null;
}
continue;
}
Expand Down
31 changes: 31 additions & 0 deletions wants/180227d4-332e-4ded-93e0-8d587f8ab215.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: I want upload hints for browsers to open appropriate system folders in the file picker
date: 2025-10-31T16:54:44.670Z
submitter: Tactile-Taco
number: 180227d4-332e-4ded-93e0-8d587f8ab215
tags:
- html
- forms
- api
discussion: https://github.com/WebWeWant/webwewant.fyi/discussions/676
status: discussing
related:
- title: File API Specification
url: https://w3c.github.io/FileAPI/
type: spec
- title: HTML input element
url: https://html.spec.whatwg.org/#the-input-element
type: spec
---

Navigating my filesystem every time I need to upload something to a website is a time-consuming pain. When I click to upload a file—whether it's my resume for a job application, a photo for a profile, or a document for a form—the file browser always opens in my home folder or the last-used location. From there, I have to navigate through multiple folders to find what I need.

I want upload fields to provide hints about what type of file I'm uploading so the browser can intelligently open the file picker in the most appropriate folder. For example, when uploading a resume to a job application, the browser could open directly to my "Career" folder or wherever my resume is stored. When uploading a photo, it could open to my Pictures folder.

The browser could use various signals to determine the best location:
- Semantic hints from the webpage (e.g., `accept` attribute, form field labels, or additional metadata)
- User's file organization patterns and frequently accessed folders
- Previous upload history for similar file types
- Common file naming patterns (e.g., files containing "resume" or "CV")

This would save time and reduce friction in the upload process, making web forms feel more intelligent and user-friendly.
Loading