Custom Code, Scripts and Publish

First of all, great software. I already love it after a few days of testing!

But, there are a few little things that make life difficult. I am aware that it is exclusively a front-end programming tool, but:

  1. Custom code must be able to be placed before the <!DOCTYPE html>. For example, how should I start PHP sessions or perform token verifications?

  2. A custom bash script would be a solution, but does not help me with publishing, because a script is not used for publishing, but only for export. I have tried to create a custom bash script, which sets my PHP code via shell script before the <!DOCTYPE html> (sed replace). Works so far, but only when exporting. Not when publishing! Now I have to export first, and then copy manually, which is really annoying…

The way I got around this was installing:

then something like this in my export script:

cd %1
rem --------------------------------
rem your PHP changes here
rem --------------------------------

rem Upload to server:
rem Launch Homepage in browser:
start ""

Other ftp clients allow script but I found ncftp to be the easiest

1 Like

This should be handled after export with a export script to avoid the html validator from spitting out errors and corrupting the code. I have one function (of many) in my python export script that checks for a div with the class of ee_frontmatter which is stored at the bottom of my pages (css d-none) using the custom code component labeled by page file name that contains all the configuration code. That is turned into a one line string, the div deleted, and stored and then called before the recreation of the html that has been parsed using the b4 soup. The result is the frontmatter, and then the template on every page.

def get_ee_frontmatter(soup):
    ee_frontmatter_div = soup.find('div', {'class': 'ee_frontmatter'})
    if ee_frontmatter_div:
        # Join all lines into a single line and replace newline characters
        ee_frontmatter = ' '.join(line.strip() for line in ee_frontmatter_div.get_text().split('\n'))
        # Remove the frontmatter div from the soup object
        return ee_frontmatter
    return ""

I export to a vhost folder in XAMPP local and then after testing upload FTP. I like the idea of adding a auto upload option myself though and have thought about adding a option inside a Bootstrap Studio file that could be toggled on or off that the export script would check to see if it should upload directly after its finished or skip. :snake:

Hi there. Thanks both for your answers.
Additional Software is not a option for me. It must be working like plain and easy.

My current script looks like:

# Add a PHP include in the first line of HTML files to perform sessions or other verifications. 

# Change to main directory;
cd "$1";

# Add php line to single file;
# echo '<?php include('verification.php'); ?>' | cat - index.html > temp && mv temp index.html

# Add php to all html files;
find "$1" -type f -name '*.html' -exec bash -c '
    for file do
        echo "<?php include(\"/srv/verification.php\"); ?>" | cat - "$file" > temp && mv temp "$file"
' bash {} +

This search all my html files and add a include to my php file.

But… It would be great if the export scripts run also on publish…

What about a webhook listener on your server that everytime you published it would run the bash script ? You might even be able to upload your bash as a .html using the custom code and then when you go to call it you first change it back to a bash file and then run it using the webhook if you need local edit/update control over the bash code in the future.

i set now a javascript variable: publish = true/false. This i can edit in Bootstrap Studio, and my export script parse the variable. If true i use rsync to copy my files to the web server in the export script.

Then the export script is my publish, and the publish function in Bootstrap Studio is set to null.

1 Like