@@ -102,8 +102,11 @@ export async function handler({ input }: ActionContext): Promise<OutputObject> {
102
102
}
103
103
104
104
function extractIdsFromUrl ( url : string ) : { docId : string , pageName : string } {
105
+ console . log ( 'Extracting IDs from URL:' , url ) ;
105
106
const urlObj = new URL ( url ) ;
107
+ console . log ( 'URL object:' , urlObj ) ;
106
108
const pathParts = urlObj . pathname . split ( '/' ) . filter ( Boolean ) ;
109
+ console . log ( 'Path parts:' , pathParts ) ;
107
110
108
111
if ( pathParts . length < 2 ) {
109
112
throw new Error ( 'Invalid Coda URL format' ) ;
@@ -112,12 +115,22 @@ function extractIdsFromUrl(url: string): { docId: string, pageName: string } {
112
115
let docId = '' ;
113
116
let pageName = '' ;
114
117
115
- // Check if the URL is in the format https://coda.io/d/_d{docId}/{pageName}
116
- if ( pathParts [ 0 ] === 'd' && pathParts [ 1 ] . startsWith ( '_d' ) ) {
117
- docId = pathParts [ 1 ] . slice ( 2 ) ; // Remove '_d' prefix
118
- pageName = pathParts [ 2 ] || '' ; // Page name is the third part, if present
118
+ console . log ( 'First path part:' , pathParts [ 0 ] ) ;
119
+ console . log ( 'Second path part:' , pathParts [ 1 ] ) ;
120
+
121
+ if ( pathParts [ 0 ] === 'd' ) {
122
+ const docIdParts = pathParts [ 1 ] . split ( '_' ) ;
123
+ if ( docIdParts . length > 1 ) {
124
+ docId = docIdParts [ docIdParts . length - 1 ] ; // Get the last part after splitting by '_'
125
+ docId = docId . startsWith ( 'd' ) ? docId . slice ( 1 ) : docId ; // Remove leading 'd' if present
126
+ pageName = pathParts [ 2 ] || '' ; // Page name is the third part, if present
127
+ console . log ( 'Extracted Doc ID:' , docId ) ;
128
+ console . log ( 'Extracted Page Name:' , pageName ) ;
129
+ } else {
130
+ throw new Error ( 'Unable to extract Doc ID from the provided URL' ) ;
131
+ }
119
132
} else {
120
- throw new Error ( 'Unable to extract Doc ID from the provided URL' ) ;
133
+ throw new Error ( 'Invalid Coda URL format ' ) ;
121
134
}
122
135
123
136
return { docId, pageName } ;
0 commit comments