# lektor-gae #

lektor-gae publishes your [Lektor](https://github.com/lektor/lektor) project to Google App Engine.

## Getting started ##

You need to have a Google App Engine instance ready, and you need to know
the application id. Ideally, the instance will be new or empty, since
the generated site will completely replace any existing application.

You also need to have the Google App Engine Python/PHP SDK installed, and
appcfg.py needs to be in the system PATH environment variable.

Refer to the [Google App Engine Documentation](https://cloud.google.com/appengine/docs)
for more details about how to get up and running.


## Installation and Usage ##

The plugin can be installed in the usual manner. In your project folder, run

```console
lektor plugins add lektor-gae
```

Then, add an app to your project. In its project file, add the following:

```ini
[servers.gae]
name = Some Descriptive Name
enabled = yes
target = gae://YOUR-APP-ID[/VERSION]
```

Replace YOUR-APP-ID with your particular app id; optionally, specify a
version. If no version is specified, it will default to 1.

Now, `lektor deploy` will generate the necessary app.yaml and call
appcfg.py to deploy your application.


## Scripting ##

Any files with `.php` extension will be uploaded and executable. It is
therefore possible to add PHP scripts to either the `assets` folder or
to add Lektor pages with `.php` extension for dynamic generation.

Two special cases (below) provide some rudimentary HTTP response codes.


## Page not found ##

If `404.php` exists in the root of your site, then it will be
invoked as the final fallback (i.e. when the requested path doesn't
match any of your published pages). Note that if you don't provide a
`404.php`, then you will have GAE's default behavior, which is a 404
HTTP code without any page content. Below is a simple 404 script
which could be placed under `assets`. It includes 404.html, which
could presumably be generated by Lektor:

```php
<?php http_response_code(404); require('404.html'); ?>
```

## Canonical URLs ##

If `301.php` exists in the root of your site, then it will be
invoked when a trailing slash is not included in the request for a
page. This helps provide consistent URLs for all pages on the site.
Below is a simple 301 script which provides the redirect. Note that
it needs to be a template, as currently written; it could be placed
under `assets` if the site base URL were hard-coded.

```php
<?php
$url = '{{ ('/'|url(external=True))[:-1] }}'.strtok($_SERVER['REQUEST_URI'],'?').'/';
header('Location: '.$url, TRUE, 301);
?>
```


## Contributing ##

Pull requests are encouraged! Once accepted, changes are published
using lektor with `lektor dev publish-plugin`.

Add readme file, prepare to publish
Add readme file, prepare to publish