Comments (8)
Thank you both for your incredible work! Worked absolutely smooth ❤️
from kirby-focus.
I just tried it out and it worked perfectly!
Maybe this can be included as an cli command for this plugin?
from kirby-focus.
something like this?
<?php
declare(strict_types=1);
use Kirby\CLI\CLI;
use Kirby\Filesystem\F;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Str;
return [
// Author: Bnomei
// WARNING: this is a destructive command. Make a backup first!
//
// site/commands/focus-k4.php
// php vendor/bin/kirby focus-k4 --dry-run
//
'description' => 'Migrate from Focus plugin to native K4',
'args' => [
'verbose' => [
'shortPrefix' => 'v',
'longPrefix' => 'verbose',
'description' => 'Verbose output',
'defaultValue' => false,
'noValue' => true,
],
'dryrun' => [
'longPrefix' => 'dry-run',
'description' => 'Dry run',
'defaultValue' => false,
'noValue' => true,
],
],
'command' => static function (CLI $cli): void {
// https://github.com/flokosiol/kirby-focus/issues/75
$files = \Symfony\Component\Finder\Finder::create()
->in(kirby()->roots()->content())
->name('*.txt')
->files();
$processed = 0;
$replacements = 0;
$isDryRun = $cli->arg('dryrun');
$isVerbose = $cli->arg('verbose');
foreach ($files as $file) {
$path = $file->getPathname();
$relpath = $file->getRelativePathname();
$content = F::read($path);
if (!Str::contains($content, 'Focus: ')) {
if ($isVerbose) {
$cli->out("⏩ {$relpath}");
}
continue;
}
$content = preg_replace_callback('/^Focus: {(.*)}$/mi', function ($matches) use ($cli) {
$json = json_decode('{' . $matches[1] . '}', true);
if (!is_array($json)) {
return $matches[0]; // no change
}
$x = A::get($json, 'x', 0);
$y = A::get($json, 'y', 0);
$x = number_format($x * 100, 0);
$y = number_format($y * 100, 0);
return "Focus: {$x}% {$y}%";
}, $content, -1, $count);
if (!$isDryRun) {
F::write($path, $content);
}
if ($count === 0 && $isVerbose) {
$cli->out("⏩ [0] {$relpath}");
}
if ($count > 0) {
$cli->out("✅ [{$count}] {$relpath}");
}
$processed++;
$replacements += $count;
}
$cli->success("files: {$processed}, replacements: {$replacements}");
}
];
from kirby-focus.
In general, Kirby plugins upload the vendor folder to git for people that don't use composer.
from kirby-focus.
Thank you so much for your kind words! @FynnZW
And also thank you for sharing your solution to migrate to Kirby v4. I'm sure it will help others.
from kirby-focus.
Maybe make a CLI command that migrates the content?
from kirby-focus.
I startet to integrate the command into the plugin structure, but I faced one problem. I got an error, because \Symfony\Component\Finder\Finder
could not be found. After adding it to the composer.json
file of the plugin everything went smooth, but not everyone uses Composer. What will happen to those folks? Anyone else running into this issue? Should be Composer setup mandatory if you want to use the command? What do you think?
And of course … THANK YOU @bnomei for taking the time to write the command and for sharing it! Very much appreciated!
And secondly, sorry for the late response 🙂
from kirby-focus.
Because I wanted to use it as a global command I replaced the Symfony stuff with a native RecursiveIteratorIterator:
<?php
declare(strict_types=1);
use Kirby\CLI\CLI;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Str;
return [
// Author: Bnomei
// WARNING: this is a destructive command. Make a backup first!
//
// site/commands/focus-k4.php
// php vendor/bin/kirby focus-k4 --dry-run
//
'description' => 'Migrate from Focus plugin to native K4',
'args' => [
'verbose' => [
'shortPrefix' => 'v',
'longPrefix' => 'verbose',
'description' => 'Verbose output',
'defaultValue' => false,
'noValue' => true,
],
'dryrun' => [
'longPrefix' => 'dry-run',
'description' => 'Dry run',
'defaultValue' => false,
'noValue' => true,
],
],
'command' => static function (CLI $cli): void {
// https://github.com/flokosiol/kirby-focus/issues/75
$directory = kirby()->roots()->content();
$processed = 0;
$replacements = 0;
$isDryRun = $cli->arg('dryrun');
$isVerbose = $cli->arg('verbose');
$filenames = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::SELF_FIRST);
foreach ($filenames as $filename) {
$filepath = $filename->getPathname();
$relpath = str_replace($directory . '/', '', $filepath);
if ($filename->isDir() || pathinfo($filepath, PATHINFO_EXTENSION) !== 'txt') {
continue;
}
$content = file_get_contents($filepath);
if (!Str::contains($content, 'Focus: ')) {
if ($isVerbose) {
$cli->out("⏩ {$relpath}");
}
continue;
}
$content = preg_replace_callback('/^Focus: {(.*)}$/mi', function ($matches) use ($cli) {
$json = json_decode('{' . $matches[1] . '}', true);
if (!is_array($json)) {
return $matches[0]; // no change
}
$x = A::get($json, 'x', 0);
$y = A::get($json, 'y', 0);
$x = number_format($x * 100, 0);
$y = number_format($y * 100, 0);
return "Focus: {$x}% {$y}%";
}, $content, -1, $count);
if (!$isDryRun) {
file_put_contents($filepath, $content);
}
if ($count === 0 && $isVerbose) {
$cli->out("⏩ [0] {$relpath}");
}
if ($count > 0) {
$cli->out("✅ [{$count}] {$relpath}");
}
$processed++;
$replacements += $count;
}
$cli->success("files processed: {$processed}, replacements: {$replacements}");
}
];
from kirby-focus.
Related Issues (20)
- kirby3-colorist supports 'Focus' HOT 4
- Does not create cropped images on server HOT 5
- Update focus field on `file.replace` HOT 4
- Transparent PNG Problem HOT 1
- Does not play nice with `translate: false` HOT 1
- WebP Support HOT 12
- [Question] Is the support for Kirby Block previews planned HOT 1
- focusSrcset does not update URL on focus point changes HOT 11
- New Kirby 3.6 Feature to support multiple mime-types is not working with this plugin for GD. HOT 3
- WebP and AVIF generated images put into wrong folder in v3.0.8 HOT 26
- Kirby 3.5.x not supported in v3.0.8 HOT 7
- [Question] multiple focus fields HOT 2
- CSS not being loaded HOT 2
- Reset focuspoint HOT 1
- Optional color fading ? HOT 2
- Preview missing for svg HOT 2
- value without effect for foxi HOT 1
- avif files do not get cropped or resized HOT 1
- Correct URL to "Setting a focus point" in readme HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kirby-focus.