docs: doc updates for lektor/lektor#1143

This commit is contained in:
Jeff Dairiki 2023-05-04 13:19:10 -07:00
parent fa73e1db27
commit 285f805c91
1 changed files with 9 additions and 4 deletions

View File

@ -18,9 +18,7 @@ and reports an error.
The parameters to the function are as follows: The parameters to the function are as follows:
* `target_url`: a URL object with the parsed URL. This object comes from the * `target_url`: the target URL as a string.
Werkzeug library and gives access to the individual parts of a URL by the
exposed attributes ([Read about the URL object :ext](https://werkzeug.palletsprojects.com/en/2.0.x/urls/)).
* `credentials`: an optional dictionary with command line supplied credentials. * `credentials`: an optional dictionary with command line supplied credentials.
Note that these credentials might be completely absent and the keys which are Note that these credentials might be completely absent and the keys which are
provided might change with future versions of Lektor. provided might change with future versions of Lektor.
@ -30,6 +28,8 @@ The parameters to the function are as follows:
Each line in the generator must be a string which is then either logged to Each line in the generator must be a string which is then either logged to
the output in the console or in the deploy/publish window in the admin UI. the output in the console or in the deploy/publish window in the admin UI.
!! Prior to Lektor version 3.4, the `target_url` parameter was passed an instance of [`werkzeug.urls.URL` :ext](https://werkzeug.palletsprojects.com/en/2.3.x/urls/#werkzeug.urls.URL) rather than a `str`.
## Example ## Example
This example implements a simple publisher that just copies all built files This example implements a simple publisher that just copies all built files
@ -38,14 +38,19 @@ into a new location.
```python ```python
import os import os
import shutil import shutil
from urllib.parse import urlsplit
from lektor.publisher import Publisher from lektor.publisher import Publisher
class CopyPublisher(Publisher): class CopyPublisher(Publisher):
def publish(self, target_url, credentials=None, **extra): def publish(self, target_url, credentials=None, **extra):
# Tip: Coerce target_url to str for compatibility with
# Lektor < 3.4.0 where target_url was a werkzeug.urls.URL
# instance rather than a str
target = urlsplit(str(target_url))
src_path = self.output_path src_path = self.output_path
dst_path = target_url.path dst_path = target.path
strip = len(src_path) + 1 strip = len(src_path) + 1
for path, folders, filenames in os.walk(src_path): for path, folders, filenames in os.walk(src_path):