Skip to content

Commit 15aac45

Browse files
authored
Modify workflowDemo function to try to serve local JSON (n8n-io#2584)
1 parent 828afaa commit 15aac45

9 files changed

+50
-71
lines changed

docs/_includes/examples-color-key.html _snippets/examples-color-key.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
To load the template into your n8n instance:
22

3-
1. [Download the workflow JSON file](/_workflows/[[ page.meta.workflowFile ]]){:target=_blank .external-link}.
3+
1. Download the workflow JSON file.
44
1. Open a new workflow in your n8n instance.
55
1. Copy in the JSON, or select **Workflow menu** <span class="inline-image">![Workflow menu icon](/_images/common-icons/three-dots-horizontal.png){.off-glb}</span> > **Import from file...**.
66

docs/advanced-ai/examples/agent-chain-comparison.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
contentType: explanation
44
title: Agents vs chains
55
description: A workflow example that demonstrates key differences between agents and chains.
6-
workflowFile: advanced-ai/examples/agents_vs_chains.json
76
---
87

98
# Demonstration of key differences between agents and chains
109

1110
In this workflow you can choose whether your chat query goes to an agent or chain. It shows some of the ways that agents are more powerful than chains.
1211

13-
14-
<figure markdown>
15-
!["Screenshot of the workflow"](/_images/advanced-ai/examples/agents-vs-chains.png)
16-
<figcaption markdown>[Download the example workflow](/_workflows/[[ page.meta.workflowFile ]])</figcaption>
17-
</figure>
12+
[[ workflowDemo("file:///advanced-ai/examples/agents_vs_chains.json") ]]
1813

1914
## Key features
2015

@@ -28,4 +23,4 @@ This workflow uses:
2823

2924
## Using the example
3025

31-
[[% include "_includes/examples-color-key.html" %]]
26+
--8<-- "_snippets/examples-color-key.md"

docs/advanced-ai/examples/api-workflow-tool.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
contentType: howto
44
title: Call an API to fetch data
55
description: Use the n8n workflow tool to load data from an API using the HTTP Request node into your AI workflow.
6-
workflowFile: advanced-ai/examples/let_your_ai_call_an_api.json
76
---
87

98
# Call an API to fetch data
109

1110
Use n8n to bring data from any API to your AI. This workflow uses the [Chat Trigger](/integrations/builtin/core-nodes/n8n-nodes-langchain.chattrigger/) to provide the chat interface, and the [Custom n8n Workflow Tool](/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolworkflow/) to call a second workflow that calls the API. The second workflow uses AI functionality to refine the API request based on the user's query.
1211

13-
<figure markdown>
14-
!["Screenshot of the two workflows in this example"](/_images/advanced-ai/examples/call-api-from-chat.png)
15-
<figcaption markdown>[Download the example workflow](/_workflows/[[ page.meta.workflowFile ]])</figcaption>
16-
</figure>
12+
[[ workflowDemo("file:///advanced-ai/examples/let_your_ai_call_an_api.json") ]]
1713

1814
## Key features
1915

@@ -26,4 +22,4 @@ This workflow uses:
2622

2723
## Using the example
2824

29-
[[% include "_includes/examples-color-key.html" %]]
25+
--8<-- "_snippets/examples-color-key.md"

docs/advanced-ai/examples/data-google-sheets.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
contentType: howto
44
title: Chat with a Google Sheet using AI
55
description: Use the n8n workflow tool to load data from Google Sheets into your AI workflow.
6-
workflowFile: advanced-ai/examples/chat_with_google_sheets_docs_version.json
76
---
87

98
# Chat with a Google Sheet using AI
109

1110
Use n8n to bring your own data to AI. This workflow uses the [Chat Trigger](/integrations/builtin/core-nodes/n8n-nodes-langchain.chattrigger/) to provide the chat interface, and the [Custom n8n Workflow Tool](/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolworkflow/) to call a second workflow that queries Google Sheets.
1211

13-
<figure markdown>
14-
!["Screenshot of the two workflows in this example"](/_images/advanced-ai/examples/chat-with-google-sheets.png)
15-
<figcaption markdown>[Download the example workflow](/_workflows/[[ page.meta.workflowFile ]])</figcaption>
16-
</figure>
12+
[[ workflowDemo("file:///advanced-ai/examples/chat_with_google_sheets_docs_version.json") ]]
1713

1814
## Key features
1915

@@ -26,4 +22,4 @@ This workflow uses:
2622

2723
## Using the example
2824

29-
[[% include "_includes/examples-color-key.html" %]]
25+
--8<-- "_snippets/examples-color-key.md"

docs/advanced-ai/examples/human-fallback.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
contentType: howto
44
title: Set a human fallback for AI workflows
55
description: Have a workflow that triggers a human answer when the AI can't help.
6-
workflowFile: advanced-ai/examples/ask_a_human.json
76
---
87

98
# Have a human fallback for AI workflows
@@ -12,10 +11,7 @@ This is a workflow that tries to answer user queries using the standard GPT-4 mo
1211

1312
This workflow uses the [Chat Trigger](/integrations/builtin/core-nodes/n8n-nodes-langchain.chattrigger/) to provide the chat interface, and the [Custom n8n Workflow Tool](/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolworkflow/) to call a second workflow that handles checking for email addresses and sending the Slack message.
1413

15-
<figure markdown>
16-
!["Screenshot of the two workflows in this example"](/_images/advanced-ai/examples/ask-a-human.png)
17-
<figcaption markdown>[Download the example workflow](/_workflows/[[ page.meta.workflowFile ]])</figcaption>
18-
</figure>
14+
[[ workflowDemo("file:///advanced-ai/examples/ask_a_human.json") ]]
1915

2016
## Key features
2117

@@ -27,4 +23,4 @@ This workflow uses:
2723

2824
## Using the example
2925

30-
[[% include "_includes/examples-color-key.html" %]]
26+
--8<-- "_snippets/examples-color-key.md"

docs/advanced-ai/examples/vector-store-website.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
contentType: howto
44
title: Populate a Pinecone vector database from a website
55
description: Scrape a website, load the data into Pinecone, then query it using a chat workflow.
6-
workflowFile: advanced-ai/examples/populate_a_pinecone_vector_database_from_a_website.json
76
---
87

98
# Populate a Pinecone vector database from a website
109

1110
Use n8n to scrape a website, load the data into Pinecone, then query it using a chat workflow. This workflow uses the [HTTP node](/integrations/builtin/core-nodes/n8n-nodes-base.httprequest/) to get website data, extracts the relevant content using the [HTML node](/integrations/builtin/core-nodes/n8n-nodes-base.html/), then uses the [Pinecone Vector Store node](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstorepinecone/) to send it to Pinecone.
1211

13-
<figure markdown>
14-
!["Screenshot of the two workflows in this example"](/_images/advanced-ai/examples/vector-store-website.png)
15-
<figcaption markdown>[Download the example workflow](/_workflows/[[ page.meta.workflowFile ]])</figcaption>
16-
</figure>
12+
[[ workflowDemo("file:///advanced-ai/examples/populate_a_pinecone_vector_database_from_a_website.json") ]]
1713

1814
## Key features
1915

@@ -27,4 +23,4 @@ This workflow uses:
2723

2824
## Using the example
2925

30-
[[% include "_includes/examples-color-key.html" %]]
26+
--8<-- "_snippets/examples-color-key.md"

docs/credentials/add-edit-credentials.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#https://www.notion.so/n8n/Frontmatter-432c2b8dff1f43d4b1c8d20075510fe4
33
description: Creating and editing credentials.
44
contentType: howto
5-
workflowFile: credentials/dynamic_credentials_using_expressions.json
65
---
76

87
# Create and edit credentials
@@ -31,11 +30,8 @@ You can use expressions to set credentials dynamically as your workflow runs:
3130

3231
### Example workflow
3332

34-
<figure markdown>
35-
!["Screenshot of the two workflows in this example"](/_images/credentials/dynamic-creds-example-workflow.png)
36-
<figcaption markdown>[Download the example workflow](/_workflows/[[ page.meta.workflowFile ]])</figcaption>
37-
</figure>
33+
[[ workflowDemo("file:///credentials/dynamic_credentials_using_expressions.json") ]]
3834

3935
#### Using the example
4036

41-
[[% include "_includes/examples-color-key.html" %]]
37+
--8<-- "_snippets/examples-color-key.md"

docs/integrations/builtin/core-nodes/n8n-nodes-base.form.md

+3-17
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
title: n8n Form node documentation
44
description: Documentation for the n8n Form node in n8n, a workflow automation platform. Includes guidance on usage and links to examples.
55
contentType: integration
6-
workflowFile: integrations/builtin/core-nodes/n8n-nodes-base.form/mutually-exclusive-branching.json
76
---
87

98
# n8n Form node
109

1110
Use the n8n Form node to create user-facing forms with multiple steps. You can add other nodes with custom logic between to process user input. You must start the workflow with the [n8n Form Trigger](/integrations/builtin/core-nodes/n8n-nodes-base.formtrigger/).
1211

13-
<figure markdown>
14-
!["Screenshot of a workflow using the Form node"](/_images/integrations/builtin/core-nodes/n8n-nodes-base.form/example_image.png)
15-
<figcaption markdown>A multi-page form with branching</figcaption>
16-
</figure>
12+
[[ workflowDemo("file:///integrations/builtin/core-nodes/n8n-nodes-base.form/mutually-exclusive-branching.json") ]]
1713

1814
## Setting up the node
1915

@@ -153,10 +149,7 @@ Form workflows containing mutually exclusive branches work as expected. n8n will
153149

154150
This workflow demonstrates mutually exclusive branching. Each selection can only execute a single branch.
155151

156-
<figure markdown>
157-
!["Screenshot of a workflow with mutually exclusive branching"](/_images/integrations/builtin/core-nodes/n8n-nodes-base.form/mutually-exclusive-branching.png)
158-
<figcaption markdown>[Download the example workflow](/_workflows/[[ page.meta.workflowFile ]])</figcaption>
159-
</figure>
152+
[[ workflowDemo("file:///integrations/builtin/core-nodes/n8n-nodes-base.form/mutually-exclusive-branching.json") ]]
160153

161154
#### Workflows that may execute multiple branches
162155

@@ -166,14 +159,7 @@ n8n only executes a single **Form Ending** n8n Form node for each execution. Whe
166159

167160
This workflow may execute more than one branch during an execution. Here, n8n executes all valid branches sequentially. This impacts which n8n Form nodes n8n executes (in particular, which **Form Ending** node displays):
168161

169-
<figure markdown>
170-
!["Screenshot of a workflow that can execute multiple branches"](/_images/integrations/builtin/core-nodes/n8n-nodes-base.form/multiple-branch-execution.png)
171-
<figcaption markdown>[Download the example workflow](/_workflows/integrations/builtin/core-nodes/n8n-nodes-base.form/multiple-branch-execution.json)</figcaption>
172-
</figure>
173-
174-
#### Using the examples
175-
176-
[[% include "_includes/examples-color-key.html" %]]
162+
[[ workflowDemo("file:///integrations/builtin/core-nodes/n8n-nodes-base.form/multiple-branch-execution.json") ]]
177163

178164
### Node options
179165

main.py

+34-16
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
def define_env(env):
1010

1111
no_template = os.environ.get('NO_TEMPLATE', False)
12-
12+
1313
# Define the character map and locales as in the original JavaScript version
1414
CHAR_MAP = {"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","¢":"cent","£":"pound","¤":"currency","¥":"yen","©":"(c)","ª":"a","®":"(r)","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"ss","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"DJ","đ":"dj","Ē":"E","ē":"e","Ė":"E","ė":"e","Ę":"e","ę":"e","Ě":"E","ě":"e","Ğ":"G","ğ":"g","Ģ":"G","ģ":"g","Ĩ":"I","ĩ":"i","Ī":"i","ī":"i","Į":"I","į":"i","İ":"I","ı":"i","Ķ":"k","ķ":"k","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","Ō":"O","ō":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ŕ":"R","ŕ":"r","Ř":"R","ř":"r","Ś":"S","ś":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ũ":"U","ũ":"u","Ū":"u","ū":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","Ə":"E","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Lj":"LJ","lj":"lj","Nj":"NJ","nj":"nj","Ș":"S","ș":"s","Ț":"T","ț":"t","ə":"e","˚":"o","Ά":"A","Έ":"E","Ή":"H","Ί":"I","Ό":"O","Ύ":"Y","Ώ":"W","ΐ":"i","Α":"A","Β":"B","Γ":"G","Δ":"D","Ε":"E","Ζ":"Z","Η":"H","Θ":"8","Ι":"I","Κ":"K","Λ":"L","Μ":"M","Ν":"N","Ξ":"3","Ο":"O","Π":"P","Ρ":"R","Σ":"S","Τ":"T","Υ":"Y","Φ":"F","Χ":"X","Ψ":"PS","Ω":"W","Ϊ":"I","Ϋ":"Y","ά":"a","έ":"e","ή":"h","ί":"i","ΰ":"y","α":"a","β":"b","γ":"g","δ":"d","ε":"e","ζ":"z","η":"h","θ":"8","ι":"i","κ":"k","λ":"l","μ":"m","ν":"n","ξ":"3","ο":"o","π":"p","ρ":"r","ς":"s","σ":"s","τ":"t","υ":"y","φ":"f","χ":"x","ψ":"ps","ω":"w","ϊ":"i","ϋ":"y","ό":"o","ύ":"y","ώ":"w","Ё":"Yo","Ђ":"DJ","Є":"Ye","І":"I","Ї":"Yi","Ј":"J","Љ":"LJ","Њ":"NJ","Ћ":"C","Џ":"DZ","А":"A","Б":"B","В":"V","Г":"G","Д":"D","Е":"E","Ж":"Zh","З":"Z","И":"I","Й":"J","К":"K","Л":"L","М":"M","Н":"N","О":"O","П":"P","Р":"R","С":"S","Т":"T","У":"U","Ф":"F","Х":"H","Ц":"C","Ч":"Ch","Ш":"Sh","Щ":"Sh","Ъ":"U","Ы":"Y","Ь":"","Э":"E","Ю":"Yu","Я":"Ya","а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ж":"zh","з":"z","и":"i","й":"j","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"ch","ш":"sh","щ":"sh","ъ":"u","ы":"y","ь":"","э":"e","ю":"yu","я":"ya","ё":"yo","ђ":"dj","є":"ye","і":"i","ї":"yi","ј":"j","љ":"lj","њ":"nj","ћ":"c","ѝ":"u","џ":"dz","Ґ":"G","ґ":"g","Ғ":"GH","ғ":"gh","Қ":"KH","қ":"kh","Ң":"NG","ң":"ng","Ү":"UE","ү":"ue","Ұ":"U","ұ":"u","Һ":"H","һ":"h","Ә":"AE","ә":"ae","Ө":"OE","ө":"oe","Ա":"A","Բ":"B","Գ":"G","Դ":"D","Ե":"E","Զ":"Z","Է":"E\'","Ը":"Y\'","Թ":"T\'","Ժ":"JH","Ի":"I","Լ":"L","Խ":"X","Ծ":"C\'","Կ":"K","Հ":"H","Ձ":"D\'","Ղ":"GH","Ճ":"TW","Մ":"M","Յ":"Y","Ն":"N","Շ":"SH","Չ":"CH","Պ":"P","Ջ":"J","Ռ":"R\'","Ս":"S","Վ":"V","Տ":"T","Ր":"R","Ց":"C","Փ":"P\'","Ք":"Q\'","Օ":"O\'\'","Ֆ":"F","և":"EV","ء":"a","آ":"aa","أ":"a","ؤ":"u","إ":"i","ئ":"e","ا":"a","ب":"b","ة":"h","ت":"t","ث":"th","ج":"j","ح":"h","خ":"kh","د":"d","ذ":"th","ر":"r","ز":"z","س":"s","ش":"sh","ص":"s","ض":"dh","ط":"t","ظ":"z","ع":"a","غ":"gh","ف":"f","ق":"q","ك":"k","ل":"l","م":"m","ن":"n","ه":"h","و":"w","ى":"a","ي":"y","ً":"an","ٌ":"on","ٍ":"en","َ":"a","ُ":"u","ِ":"e","ْ":"","٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9","پ":"p","چ":"ch","ژ":"zh","ک":"k","گ":"g","ی":"y","۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9","฿":"baht","ა":"a","ბ":"b","გ":"g","დ":"d","ე":"e","ვ":"v","ზ":"z","თ":"t","ი":"i","კ":"k","ლ":"l","მ":"m","ნ":"n","ო":"o","პ":"p","ჟ":"zh","რ":"r","ს":"s","ტ":"t","უ":"u","ფ":"f","ქ":"k","ღ":"gh","ყ":"q","შ":"sh","ჩ":"ch","ც":"ts","ძ":"dz","წ":"ts","ჭ":"ch","ხ":"kh","ჯ":"j","ჰ":"h","Ṣ":"S","ṣ":"s","Ẁ":"W","ẁ":"w","Ẃ":"W","ẃ":"w","Ẅ":"W","ẅ":"w","ẞ":"SS","Ạ":"A","ạ":"a","Ả":"A","ả":"a","Ấ":"A","ấ":"a","Ầ":"A","ầ":"a","Ẩ":"A","ẩ":"a","Ẫ":"A","ẫ":"a","Ậ":"A","ậ":"a","Ắ":"A","ắ":"a","Ằ":"A","ằ":"a","Ẳ":"A","ẳ":"a","Ẵ":"A","ẵ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ẻ":"E","ẻ":"e","Ẽ":"E","ẽ":"e","Ế":"E","ế":"e","Ề":"E","ề":"e","Ể":"E","ể":"e","Ễ":"E","ễ":"e","Ệ":"E","ệ":"e","Ỉ":"I","ỉ":"i","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ỏ":"O","ỏ":"o","Ố":"O","ố":"o","Ồ":"O","ồ":"o","Ổ":"O","ổ":"o","Ỗ":"O","ỗ":"o","Ộ":"O","ộ":"o","Ớ":"O","ớ":"o","Ờ":"O","ờ":"o","Ở":"O","ở":"o","Ỡ":"O","ỡ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ủ":"U","ủ":"u","Ứ":"U","ứ":"u","Ừ":"U","ừ":"u","Ử":"U","ử":"u","Ữ":"U","ữ":"u","Ự":"U","ự":"u","Ỳ":"Y","ỳ":"y","Ỵ":"Y","ỵ":"y","Ỷ":"Y","ỷ":"y","Ỹ":"Y","ỹ":"y","–":"-","‘":"\'","’":"\'","“":"\\\"","”":"\\\"","„":"\\\"","†":"+","•":"*","…":"...","₠":"ecu","₢":"cruzeiro","₣":"french franc","₤":"lira","₥":"mill","₦":"naira","₧":"peseta","₨":"rupee","₩":"won","₪":"new shequel","₫":"dong","€":"euro","₭":"kip","₮":"tugrik","₯":"drachma","₰":"penny","₱":"peso","₲":"guarani","₳":"austral","₴":"hryvnia","₵":"cedi","₸":"kazakhstani tenge","₹":"indian rupee","₺":"turkish lira","₽":"russian ruble","₿":"bitcoin","℠":"sm","™":"tm","∂":"d","∆":"delta","∑":"sum","∞":"infinity","♥":"love","元":"yuan","円":"yen","﷼":"rial","ﻵ":"laa","ﻷ":"laa","ﻹ":"lai","ﻻ":"la"}
15-
15+
1616
def custom_slugify(string):
1717
if not isinstance(string, str):
1818
raise ValueError("slugify: string argument expected")
19-
19+
2020
# Process the string
2121
slug = ''.join(
2222
CHAR_MAP.get(ch, ch).replace('-', ' ')
@@ -29,10 +29,10 @@ def custom_slugify(string):
2929

3030
# Replace spaces with hyphen and convert to lowercase
3131
slug = re.sub(r'\s+', '-', slug).lower()
32-
32+
3333
return slug
3434

35-
@env.macro
35+
@env.macro
3636
def templatesWidget(title: str, slug: str, toLoad: int = 3) -> str:
3737

3838
if no_template:
@@ -84,18 +84,36 @@ def get_workflow_details(workflow: dict) -> Optional[dict]:
8484
f'</span></div>'
8585
)
8686

87-
@env.macro
88-
def workflowDemo(workflow_endpoint):
87+
@env.macro
88+
def workflowDemo(workflow_json):
8989
if no_template:
9090
return "<div class='n8n-workflow-preview'><p>Workflow preview placeholder.</p></div>"
9191

92-
# Original API request logic
93-
r = requests.get(url = workflow_endpoint)
94-
wf_data = r.json()
95-
template_url = f'https://n8n.io/workflows/{wf_data["id"]}-{wf_data["name"]}/'
96-
workflow_json = {
97-
"nodes": wf_data['workflow']['nodes'],
98-
"connections": wf_data['workflow']['connections']
99-
}
92+
parsed_workflow_url = urllib.parse.urlparse(workflow_json)
93+
94+
if parsed_workflow_url.scheme in ["https", "http"]:
95+
r = requests.get(url = workflow_json)
96+
wf_data = r.json()
97+
template_url = f'https://n8n.io/workflows/{wf_data["id"]}-{custom_slugify(wf_data["name"])}/'
98+
workflow_json = {
99+
"nodes": wf_data['workflow']['nodes'],
100+
"connections": wf_data['workflow']['connections']
101+
}
102+
workflow_message = "View template details"
103+
elif parsed_workflow_url.scheme == "file":
104+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
105+
request_path = parsed_workflow_url.path
106+
file_path = f'{BASE_DIR}/docs/_workflows{request_path}'
107+
with open(file_path, 'r') as file:
108+
wf_data = json.load(file)
109+
template_url = f'/_workflows{request_path}'
110+
workflow_json = {
111+
"nodes": wf_data['nodes'],
112+
"connections": wf_data['connections']
113+
}
114+
workflow_message = "View workflow file"
115+
else:
116+
raise ValueError("Workflow JSON must include a URL scheme")
117+
100118
encoded_workflow_json = urllib.parse.quote(json.dumps(workflow_json))
101-
return f"<div class='n8n-workflow-preview'><n8n-demo hidecanvaserrors='true' clicktointeract='true' frame='false' collapseformobile='false' workflow='{encoded_workflow_json}'></n8n-demo><a href='{template_url}' target='_blank'>View template details</a></div>"
119+
return f"<div class='n8n-workflow-preview'><n8n-demo hidecanvaserrors='true' clicktointeract='true' frame='false' collapseformobile='false' workflow='{encoded_workflow_json}'></n8n-demo><a href='{template_url}' target='_blank'>{workflow_message}</a></div>"

0 commit comments

Comments
 (0)