Plugin for changing markdown, text and html of pages automatically ("batch processing")

Hi all,

following situration:
There is a page
user/pages/01.topic/01.subtopic1/default.md
which is linked on several other pages. Now you move this page to
user/pages/02.anothertopic/01.subtopic1/default.md
all links set to this page will be broken, correct?

How do you avoid this problem?
Is there a plugin (I did not find one) to move pages including link correction automatically?

Otherwise a way to solve this issue could be a plugin in which you define a string like “subtopic1” (representing the foldername and therefor at least a part of the link) and crawl all folders and md-files to create a list with all hits. This would be your todo list to check and adapt the links manually. In a more advanced version you should be able to initiate a script which opens all affected md-files to automatically change urls.

I know one can run into other problems, e.g. if the moved subpage has the same name like another one in a different folder structure like
user/pages/01.topic/01.subtopic1/default.md
user/pages/03.importanttopic/01.subtopic1/default.md
A search for “subtopic1” would also list all md-files containing a link to user/pages/03.importanttopic/01.subtopic1/default.md although you do not need that.

Any ideas or suggestions? I don’t think that I am the first one thinking about this… (sorry, did not find a matching discussion in this forum).

Thank you and greetings,

Markus

One solution could be to define a slug for every pages, a slug that you will never change.
It’s juste an idea and other will probably have a different approach.

Hi AmauryH,

thank you for your post. Solving this issue via slugs got into my mind too, but I am not a very friend of thinking, that things will never change. So I guess, I will try to develop a plugin with which you can search for strings and change them automatically. This would not be a tool for “normal” editors, but as an admin it might help you a lot. You even could use that as a link-checker (better: find links, not a testing) or in general to find content all over your pages. At the moment it is still in an early alpha and a plain php-file, but when I finished diving into plugin-development (I just started with grav), I surely will post it here.

Till then: other ideas or approaches are still welcome! :wink:

@Markus, Finding broken links is one thing, fixing them is another…

To find them, besides creating a plugin, you could:

  • Have a look at the Index Coverage report in Google Search Console. It has a delay of course.
  • Have a look at ScreamingFrog, which reports broken links.
    The free version has a crawl limit of 500 urls.
  • Search for web crawlers and you will find (almost) ready to use Python, Node and bash scripts that crawl sites

Hi @anon76427325,

sorry, my writing “use that as a link-checker” was a bit misleading. My initial need for thinking about this developing plugin was to find grav url-structures (links) and change them if content is beeing moved. So you could “check” those links (better: find them) within all pages. A test for functionality is not intended, so you are completely right with your comment and I changed the writing in my former post.

Besides correcting links this plugin should be very helpful to change e.g. expressions you use all over your page. A headline “Downloads” for example. If you want to change it all over your site, you might have to open a dozen pages and correct that manually. At the moment my script searches for Downlods, collects all matches and lets you choose which of these matches are to be changed to Downloads for you (or whatever). It seems to be quite versatile and usable for html, markdown or “normal” text.

So I am heading further… :slight_smile:

@Markus, Are you moving the goalpost along the way?

If so, it might be an idea to change the title to something like ‘Plugin to Find/Replace text in all pages/files’ and change the initial post accordingly?

Are you aiming at non-technical (Admin) users? Else, vscode and other editors, or even plain find/sed/grep might do the job.

Hi @anon76427325,
I changed the title. Not sure, if it is useful to move it from “general” to “plugins” at this time. Sorry for my uncertainty, but I am new to grav and this forum. Need some time to acclimatize… :wink:

Are you aiming at non-technical (Admin) users? Else, vscode and other editors, or even plain find/sed/grep might do the job.

I play around at the moment and go through all the chapters of https://learn.getgrav.org/16. While doing this I stumble about several issues which are very important for me to make a decision if I stay with grav or not and so I try to find solutions - don’t care if they are already given or need to be created. And because I often develop specific functionalities, themes and plugins for individual needs are very important. I hope I can get along with that and the problem with moving already interally linked content is something, what appears different to database cms (where you simply link the id and not the path and name of a page - so you don’t run into problems when moving pages). And because moving pages is something normal, I need a solution. If there won’t be one, I would not see my future with grav. But I keep pushing and it looks good…

So, back to your question: Yes, I am aiming at non-technical users. But not real noobs because you at least should have some skills to understand what your are doing when changing code of pages which are selected. If you like, I could send you the current development file (just a php file, which is placed within the grav root folder and can be executed). Transforming that into a plugin will be exciting…

@Markus, You’re always welcome to share your code for feedback. If you prefer you may PM me.

Hello,
Just to say that a plugin that fix broken links when moving pages seems a very good idea to me, useful for non-technical users.