since I am creating websites that are very similar, I am looking for a solution that can save me some time.
Here is my situation. Lets say i have these page titles:
Good page – About us
Good page – Contact
Good page – Products
And since I am creating page for another client, I have to manually change the names to:
Awesome page – About us
Awesome page – Contact
Awesome page – Products
var originalTitle = document.title;
var newTitle = originalTitle.replace(“Good”, “Awesome”);
document.title = newTitle;
I think the way is to write some export code, but I have no idea how to do that. Can somebody help me please?
If you are not using the bss servers then you could do it with php.
<?php include 'config.php'; echo $sitename ?> | The Page Title
then add a config.php file along the lines of:
$sitename = "Awesome";
You could also add other variables such as domain name, email address etc.
Thank you. Most of the time, I am exporting via SFTP connections. But I need it for both: SFTP and file export on my drive.
I guess that export function is available only for file export on my drive?
It will work for both as long as your production server can handle php
Edit: You will have to tell the server to handle html files as php (usually 1 line in htaccess)
A html parser would work like Python Beautiful Soup. I usually just run the script after I export since the folder opens up I exported to.
from bs4 import BeautifulSoup
html_doc = '<title>My Title</title>'
soup = BeautifulSoup(html_doc, "lxml")
tag = soup.title
print("\nOriginal Markup with new text:")
tag.string = "Python Html Parser is my new Title"
Original Markup with new text:
<title>Python Html Parser is my new Title</title>
You can test the above example at Write a Python program to change the tag’s contents and replace with the given string
Obviously you would write a single script and include opening each file with python, do the soup work and save the changes for each page. Larger projects get more complex with page opening loops and if statements to target your strings and anything else in the documents but learn your basics first. Once you reach a level of understanding the payoff is enormous.