Skip to content
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

Rename font assets when theme is saved and/or exported #712

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

matiasbenedetto
Copy link
Contributor

@matiasbenedetto matiasbenedetto commented Aug 29, 2024

What?

Fonts asset files added to the theme are renamed with a human-readable name.
No functional change was added.

Why?

To make the files easy to identify.
Fixes #710

Example

Before the resulting theme.json looked like this:

 {
                    "name": "Abhaya Libre",
                    "slug": "abhaya-libre",
                    "fontFamily": "\"Abhaya Libre\", serif",
                    "fontFace": [
                        {
                            "src": "file:./assets/fonts/e3tmeuGtX-Co5MNzeAOqinEgfkPWovdU4w.woff2",
                            "fontWeight": "400",
                            "fontStyle": "normal",
                            "fontFamily": "\"Abhaya Libre\""
                        },
                        {
                            "src": "file:./assets/fonts/e3t5euGtX-Co5MNzeAOqinEYj2ryr9xI6oYtBA.woff2",
                            "fontWeight": "500",
                            "fontStyle": "normal",
                            "fontFamily": "\"Abhaya Libre\""
                        },
                        {
                            "src": "file:./assets/fonts/e3t5euGtX-Co5MNzeAOqinEYo23yr9xI6oYtBA.woff2",
                            "fontWeight": "600",
                            "fontStyle": "normal",
                            "fontFamily": "\"Abhaya Libre\""
                        },
                        {
                            "src": "file:./assets/fonts/e3t5euGtX-Co5MNzeAOqinEYx2zyr9xI6oYtBA.woff2",
                            "fontWeight": "700",
                            "fontStyle": "normal",
                            "fontFamily": "\"Abhaya Libre\""
                        },
                        {
                            "src": "file:./assets/fonts/e3t5euGtX-Co5MNzeAOqinEY22_yr9xI6oYtBA.woff2",
                            "fontWeight": "800",
                            "fontStyle": "normal",
                            "fontFamily": "\"Abhaya Libre\""
                        }
                    ]
                }

image

After the resulting theme.json looks like this:

                {
                    "fontFace": [
                        {
                            "fontFamily": "\"Abhaya Libre\"",
                            "fontStyle": "normal",
                            "fontWeight": "400",
                            "src": [
                                "file:./assets/fonts/abhaya-libre-400-normal.woff2"
                            ]
                        },
                        {
                            "fontFamily": "\"Abhaya Libre\"",
                            "fontStyle": "normal",
                            "fontWeight": "500",
                            "src": [
                                "file:./assets/fonts/abhaya-libre-500-normal.woff2"
                            ]
                        },
                        {
                            "fontFamily": "\"Abhaya Libre\"",
                            "fontStyle": "normal",
                            "fontWeight": "600",
                            "src": [
                                "file:./assets/fonts/abhaya-libre-600-normal.woff2"
                            ]
                        },
                        {
                            "fontFamily": "\"Abhaya Libre\"",
                            "fontStyle": "normal",
                            "fontWeight": "700",
                            "src": [
                                "file:./assets/fonts/abhaya-libre-700-normal.woff2"
                            ]
                        },
                        {
                            "fontFamily": "\"Abhaya Libre\"",
                            "fontStyle": "normal",
                            "fontWeight": "800",
                            "src": [
                                "file:./assets/fonts/abhaya-libre-800-normal.woff2"
                            ]
                        }
                    ],
                    "fontFamily": "\"Abhaya Libre\", serif",
                    "name": "Abhaya Libre",
                    "slug": "abhaya-libre"
                },

image

How to test

Testing 'Save theme' workflow:

  1. Create a blank theme using CBT.
  2. Install a few fonts using the Font Library
  3. Save the theme and inspect that the font files in /<theme-folder>/assets/fonts/ have human-readable names.

Testing the 'Export theme' workflow:

  1. Create a blank theme using CBT.
  2. Install a few fonts using the Font Library
  3. Export the theme and inspect that the font files in the resulting zip archive have the fonts in /<ztheme-folder>/assets/fonts/ featuring human-readable names.

Related pending issues that aren't part of this PR:

@matiasbenedetto
Copy link
Contributor Author

Updated the code to put the fonts into font-family sub folders.
Example:

                {
                    "name": "Alef",
                    "slug": "alef",
                    "fontFamily": "Alef, sans-serif",
                    "fontFace": [
                        {
                            "src": [
                                "file:./assets/fonts/alef/alef-400-normal.woff2"
                            ],
                            "fontWeight": "400",
                            "fontStyle": "normal",
                            "fontFamily": "Alef"
                        },
                        {
                            "src": [
                                "file:./assets/fonts/alef/alef-700-normal.woff2"
                            ],
                            "fontWeight": "700",
                            "fontStyle": "normal",
                            "fontFamily": "Alef"
                        }
                    ]
                },
                

Copy link
Contributor

@jffng jffng left a comment

Choose a reason for hiding this comment

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

LGTM, tested both saving and exporting with multiple fonts added to the theme works as expected.

@matiasbenedetto matiasbenedetto merged commit 4911a06 into trunk Sep 5, 2024
2 checks passed
@matiasbenedetto matiasbenedetto deleted the add/rename-font-assets branch September 5, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Should font files be renamed when added to a theme?
2 participants