Skip to content

Migration to native Focus in Kirby v4 - regex to use #75

@FynnZW

Description

@FynnZW

I don't know if this is the correct place, but I just tried to migrate existing focus points from this plugin to the new native syntax in Kirby 4.
So going from:
Focus: {"x":0.5, "y": 0.22}
to:
Focus: 50% 22%.

Converting from one decimal place to percentage (0.5 = 50%) made this not so easy.
Here's how I did it - might be useful for others.
Done with VSCode search & replace on the content folder (via regex, the .*-button)

  1. Transform X values to two decimal places
    Search:
    Focus: \{"x":(0.\d(?!\d)),"y":(0.\d+)\}
    Replace:
    Focus: {"x":$10,"y":$2}

  2. Transform Y values to two decimal places
    Search:
    Focus: \{"x":(0.\d+),"y":(0.\d(?!\d))\}
    Replace:
    Focus: {"x":$1,"y":$20}

  3. Turn to percentage syntax
    Search:
    Focus: \{"x":\d+\.(\d+?),"y":\d+\.(\d+?)\}
    Replace:
    Focus: $1% $2%

PS: Thanks a lot for this great plugin! While it won't be needed anymore soon, it made working with images in Kirby v3 so much better (I probably wouldn't have used Kirby v3 if this plugin hadn't existed).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions