Skip to content

Conversation

@Xheldon
Copy link
Contributor

@Xheldon Xheldon commented Nov 27, 2025

In Notion, if a Toggle's title is a Heading, then it is a Heading block, not Toggle🥲

@Xheldon
Copy link
Contributor Author

Xheldon commented Nov 27, 2025

I made some changes to the sanitizeFileName function; it has a wide impact, but logically there aren’t any major issues. @tgrosinger

@Xheldon Xheldon changed the title Notion API: fix the toggle convert error Notion API: fix the toggle convert & file name error Nov 27, 2025
@Xheldon Xheldon changed the title Notion API: fix the toggle convert & file name error Notion API: fix the toggle convert & file name error #458 Nov 27, 2025
@Xheldon Xheldon changed the title Notion API: fix the toggle convert & file name error #458 Notion API: fix the toggle convert & file name error Nov 27, 2025
// If the result is empty or only whitespace after sanitization, return a default name
// This prevents creating files like ".md" (no name) or folders with only spaces
const trimmed = sanitized.trim();
return trimmed || 'Untitled';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think generally this is a good change, however, in importDatabaseCore of the Notion API importer it would previously use Untitled Database if this function returned an empty value and now it will just return Untitled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, but compared to checking the return value at every sanitizeFileName function call, I don’t think it’s that important. Do you think this part must, as before, return a possible empty string value for backward compatibility?

src/util.ts Outdated
const sanitized = name
.replace(illegalRe, '')
.replace(controlRe, '')
.replace(controlRe, '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra space added.

Copy link
Contributor Author

@Xheldon Xheldon Dec 2, 2025

Choose a reason for hiding this comment

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

I run npm run lint before each commit, but occasional spacing and comment indentation issues do occur, possibly due to my editor configuration; I’ll take a closer look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


let headingText = '';
let headingPrefix = '';
let headingData: Heading1BlockObjectResponse['heading_1'] | Heading2BlockObjectResponse['heading_2'] | Heading3BlockObjectResponse['heading_3'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let headingData: Heading1BlockObjectResponse['heading_1'] | Heading2BlockObjectResponse['heading_2'] | Heading3BlockObjectResponse['heading_3'];
let headingData: HeaderContentWithRichTextAndColorResponse;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. see: 8496eff

let headingText = '';
let headingPrefix = '';
let headingData: Heading1BlockObjectResponse['heading_1'] | Heading2BlockObjectResponse['heading_2'] | Heading3BlockObjectResponse['heading_3'];
let isToggleable = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

isToggleable can be defined after the if-block below without any casting required.

const isToggleable = headingData.is_toggleable || false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that part was overly verbose, so I refactored it, along with the headingData above, see: 8496eff

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.

2 participants